Cataclysm BN
item Class Reference

#include <item.h>

Inheritance diagram for item:
visitable< item >

Classes

class  craft_data
 Data for items that represent in-progress crafts. More...
 
struct  default_charges_tag
 Suppress randomization and always start with default quantity of charges. More...
 
struct  solitary_tag
 Default (or randomized) charges except if counted by charges then only one charge. More...
 
struct  sound_data
 

Public Types

using FlagsSetType = cata::flat_set< std::string >
 
using archive_type_tag = io::object_archive_tag
 

Public Member Functions

 item ()
 
 item (item &&)
 
 item (const item &)
 
itemoperator= (item &&)
 
itemoperator= (const item &)
 
 item (const itype_id &id, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype *type, time_point turn=calendar::turn, int qty=-1)
 
 item (const itype_id &id, time_point turn, default_charges_tag)
 
 item (const itype *type, time_point turn, default_charges_tag)
 
 item (const itype_id &id, time_point turn, solitary_tag)
 
 item (const itype *type, time_point turn, solitary_tag)
 
 item (const recipe *rec, int qty, std::list< item > items, std::vector< item_comp > selections)
 For constructing in-progress crafts. More...
 
template<typename... Args>
 item (const std::string &itype, Args &&... args)
 
 ~item ()
 
safe_reference< itemget_safe_reference ()
 Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to. More...
 
itemconvert (const itype_id &new_type)
 Filter converting this instance to another type preserving all other aspects. More...
 
itemdeactivate (const Character *ch=nullptr, bool alert=true)
 Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op. More...
 
itemactivate ()
 Filter converting instance to active state. More...
 
units::energy mod_energy (const units::energy &qty)
 Add or remove energy from a battery. More...
 
itemammo_set (const itype_id &ammo, int qty=-1)
 Filter setting the ammo for this instance Any existing ammo is removed. More...
 
itemammo_unset ()
 Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present. More...
 
itemset_damage (int qty)
 Filter setting damage constrained by min_damage and max_damage. More...
 
item split (int qty)
 Splits a count-by-charges item always leaving source item with minimum of 1 charge. More...
 
const mtypeget_mtype () const
 
void set_mtype (const mtype *m)
 Sets the monster type associated with this item (corpse). More...
 
bool is_corpse () const
 Whether this is a corpse item. More...
 
bool can_revive () const
 Whether this is a corpse that can be revived. More...
 
bool ready_to_revive (const tripoint &pos) const
 Whether this corpse should revive now. More...
 
bool is_money () const
 
nc_color color () const
 Returns the default color of the item (e.g. More...
 
nc_color color_in_inventory () const
 Returns the color of the item depending on usefulness for the player character, e.g. More...
 
nc_color color_in_inventory (const player &p) const
 Returns the color of the item depending on usefulness for the passed player, e.g. More...
 
std::string tname (unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
 Return the (translated) item name. More...
 
std::string display_money (unsigned int quantity, unsigned int total, const std::optional< unsigned int > &selected=std::nullopt) const
 
std::string display_name (unsigned int quantity=1) const
 Returns the item name and the charges or contained charges (if the item can have charges at all). More...
 
std::vector< iteminfoinfo () const
 Return all the information about the item and its type as a vector. More...
 
std::vector< iteminfoinfo (int batch) const
 
std::vector< iteminfoinfo (const iteminfo_query &parts, int batch, temperature_flag temperature) const
 
std::vector< iteminfoinfo (temperature_flag temperature) const
 
std::string info_string () const
 As info, but as a string rather than a vector of properties. More...
 
std::string info_string (const iteminfo_query &parts, int batch=1, temperature_flag temperature=temperature_flag::TEMP_NORMAL) const
 
void basic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void med_info (const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void food_info (const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
 
void magazine_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void ammo_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gun_info (const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void gunmod_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_protection_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void animal_armor_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void armor_fit_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void book_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void battery_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void container_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void tool_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void component_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void repair_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void disassembly_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void qualities_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void bionic_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void combat_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void contents_info (std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
 
void final_info (std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
 
float simulate_burn (fire_data &frd) const
 Calculate all burning calculations, but don't actually apply them to item. More...
 
bool burn (fire_data &frd)
 Burns the item. More...
 
const item_categoryget_category () const
 
bool reload (player &u, item_location loc, int qty)
 Reload item using ammo from location returning true if successful. More...
 
template<typename Archive >
void io (Archive &)
 
void serialize (JsonOut &json) const
 
void deserialize (JsonIn &jsin)
 
const std::string & symbol () const
 
int price (bool practical) const
 Returns the monetary value of an item. More...
 
bool display_stacked_with (const item &rhs, bool check_components=false) const
 Whether two items should stack when displayed in a inventory menu. More...
 
bool stacks_with (const item &rhs, bool check_components=false, bool skip_type_check=false) const
 
bool merge_charges (const item &rhs)
 Merge charges of the other item into this item. More...
 
units::mass weight (bool include_contents=true, bool integral=false) const
 
units::volume volume (bool integral=false) const
 Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. More...
 
units::volume base_volume () const
 Simplified, faster volume check for when processing time is important and exact volume is not. More...
 
units::volume corpse_volume (const mtype *corpse) const
 Volume check for corpses, helper for base_volume(). More...
 
int lift_strength () const
 Required strength to be able to successfully lift the item unaided by equipment. More...
 
Melee

The functions here assume the item is used in melee, even if's a gun or not a weapon at all.

Because the functions apply to all types of items, several of the is_* functions here may return true for the same item. This only indicates that it can be used in various ways.

int attack_cost () const
 Base number of moves (Creature::moves) that a single melee attack with this items takes. More...
 
int damage_melee (damage_type dt) const
 Damage of given type caused when this item is used as melee weapon. More...
 
damage_instance base_damage_melee () const
 All damage types this item deals when used in melee (no skill modifiers etc. More...
 
damage_instance base_damage_thrown () const
 All damage types this item deals when thrown (no skill modifiers etc. More...
 
double effective_dps (const player &guy, const monster &mon) const
 Calculate the item's effective damage per second past armor when wielded by a character against a monster. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc, const player &guy) const
 calculate effective dps against a stock set of monsters. More...
 
std::map< std::string, double > dps (bool for_display, bool for_calc) const
 
double average_dps (const player &guy) const
 return the average dps of the weapon against evaluation monsters More...
 
double ideal_ranged_dps (const Character &who, gun_mode &mode) const
 
bool is_two_handed (const Character &guy) const
 Whether the character needs both hands to wield this item. More...
 
bool is_melee (damage_type dt) const
 Is this item an effective melee weapon for the given damage type? More...
 
bool is_melee () const
 Is this item an effective melee weapon for any damage type? More...
 
skill_id melee_skill () const
 The most relevant skill used with this melee weapon. More...
 
int reach_range (const Character &guy) const
 Max range of melee attack this weapon can be used for. More...
 
void set_countdown (int num_turns)
 Sets time until activation for an item that will self-activate in the future. More...
 
bool use_charges (const itype_id &what, int &qty, std::list< item > &used, const tripoint &pos, const std::function< bool(const item &)> &filter=return_true< item >)
 Consumes specified charges (or fewer) from this and any contained items. More...
 
bool on_drop (const tripoint &pos)
 Invokes item type's itype::drop_action. More...
 
bool on_drop (const tripoint &pos, map &map)
 Invokes item type's itype::drop_action. More...
 
bool use_amount (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 Consume a specific amount of items of a specific type. More...
 
bool allow_crafting_component () const
 Permits filthy components, should only be used as a helper in creating filters. More...
 
Containers

Containers come in two flavors:

bool is_container () const
 Whether this is container. More...
 
bool is_watertight_container () const
 Whether this is a container which can be used to store liquids. More...
 
bool is_container_empty () const
 Whether this item has no contents at all. More...
 
bool is_non_resealable_container () const
 Whether removing this item's contents will permanently alter it. More...
 
bool is_container_full (bool allow_bucket=false) const
 Whether this item has no more free capacity for its current content. More...
 
void fill_with (item &liquid, int amount=INFINITE_CHARGES)
 Fill item with liquid up to its capacity. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
 How much more of this liquid (in charges) can be put in this container. More...
 
int get_remaining_capacity_for_liquid (const item &liquid, const Character &p, std::string *err=nullptr) const
 
units::volume get_container_capacity () const
 It returns the total capacity (volume) of the container for liquids. More...
 
units::volume get_total_capacity () const
 It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc. More...
 
void put_in (const item &payload)
 Puts the given item into this one, no checks are performed. More...
 
item in_its_container () const
 Returns this item into its default container. More...
 
item in_container (const itype_id &container_type) const
 
bool item_has_uses_recursive () const
 
bool is_funnel_container (units::volume &bigger_than) const
 Funnel related functions. More...
 
void add_rain_to_container (bool acid, int charges=1)
 Add charge(s) of rain to given container, possibly contaminating it. More...
 
int get_quality (const quality_id &id) const
 
std::map< quality_id, int > get_qualities () const
 
bool count_by_charges () const
 
int count () const
 If count_by_charges(), returns charges, otherwise 1. More...
 
bool craft_has_charges ()
 
void mod_charges (int mod)
 Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges. More...
 
bool actualize_rot (const tripoint &pnt, temperature_flag temperature, const weather_manager &weather)
 Whether the item has to be removed as it has rotten away completely. More...
 
time_duration calc_rot (time_point time, int temp) const
 Returns rot of the item since last rot calculation. More...
 
time_duration minimum_freshness_duration (temperature_flag temperature) const
 Time that this item is guaranteed to stay fresh. More...
 
void mod_last_rot_check (time_duration processing_duration)
 This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble. More...
 
bool process_rot (const tripoint &pos)
 Update temperature for things like food Update rot for things that perish All items that rot also have temperature. More...
 
bool process_rot (bool seals, const tripoint &pos, player *carrier, temperature_flag flag, const weather_manager &weather_generator)
 
int get_comestible_fun () const
 
bool goes_bad () const
 whether an item is perishable (can rot) More...
 
bool goes_bad_after_opening () const
 whether an item is perishable (can rot), even if it is currently in a preserving container More...
 
time_duration get_shelf_life () const
 Get the shelf life of the item. More...
 
double get_relative_rot () const
 Get rot value relative to shelf life (or 0 if item does not spoil) More...
 
void set_relative_rot (double val)
 Set current item rot relative to shelf life (no-op if item does not spoil) More...
 
void set_rot (time_duration val)
 
int spoilage_sort_order () const
 Get time left to rot, ignoring fridge. More...
 
bool is_fresh () const
 an item is fresh if it is capable of rotting but still has a long shelf life remaining More...
 
bool is_going_bad () const
 an item is about to become rotten when shelf life has nearly elapsed More...
 
bool rotten () const
 returns true if item is now rotten after all shelf life has elapsed More...
 
bool has_rotten_away () const
 Whether the item has enough rot that it should get removed. More...
 
time_duration get_rot () const
 
void mod_rot (const time_duration &val)
 
time_duration brewing_time () const
 Time for this item to be fully fermented. More...
 
const std::vector< itype_id > & brewing_results () const
 The results of fermenting this item. More...
 
bool detonate (const tripoint &p, std::vector< item > &drops)
 Detonates the item and adds remains (if any) to drops. More...
 
bool will_explode_in_fire () const
 
Material(s) of the item

Each item is made of one or more materials (material_type).

Materials have properties that affect properties of the item (e.g. resistance against certain damage types).

Corpses inherit the material of the monster type.

const material_typeget_random_material () const
 Get a material reference to a random material that this item is made of. More...
 
const material_typeget_base_material () const
 Get the basic (main) material of this item. More...
 
const std::vector< material_id > & made_of () const
 The ids of all the materials this is made of. More...
 
const std::map< quality_id, int > & quality_of () const
 The ids of all the qualities this contains. More...
 
std::vector< const material_type * > made_of_types () const
 Same as made_of(), but returns the material_type directly. More...
 
bool made_of_any (const std::set< material_id > &mat_idents) const
 Check we are made of at least one of a set (e.g. More...
 
bool only_made_of (const std::set< material_id > &mat_idents) const
 Check we are made of only the materials (e.g. More...
 
bool made_of (const material_id &mat_ident) const
 Check we are made of this material (e.g. More...
 
bool contents_made_of (phase_id phase) const
 If contents nonempty, return true if item phase is same, else false. More...
 
bool made_of (phase_id phase) const
 Are we solid, liquid, gas, plasma? More...
 
std::vector< item_compget_uncraft_components () const
 Returns a list of components used to craft this item or the default components if it wasn't player-crafted. More...
 
bool conductive () const
 Whether the items is conductive. More...
 
bool flammable (int threshold=0) const
 Whether the items is flammable. More...
 
bool reinforceable () const
 Whether the item can be repaired beyond normal health. More...
 
int acid_resist (bool to_self=false, int base_env_resist=0) const
 Resistance against different damage types (damage_type). More...
 
int fire_resist (bool to_self=false, int base_env_resist=0) const
 
int bash_resist (bool to_self=false) const
 
int cut_resist (bool to_self=false) const
 
int stab_resist (bool to_self=false) const
 
int bullet_resist (bool to_self=false) const
 
void mitigate_damage (damage_unit &du) const
 Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type. More...
 
int damage_resist (damage_type dt, bool to_self=false) const
 Resistance provided by this item against damage type given by an enum. More...
 
int chip_resistance (bool worst=false) const
 Returns resistance to being damaged by attack against the item itself. More...
 
int damage () const
 How much damage has the item sustained? More...
 
int damage_level (int max) const
 Scale item damage to the given number of levels. More...
 
int min_damage () const
 Minimum amount of damage to an item (state of maximum repair) More...
 
int max_damage () const
 Maximum amount of damage to an item (state before destroyed) More...
 
float get_relative_health () const
 Relative item health. More...
 
bool mod_damage (int qty, damage_type dt)
 Apply damage to const itemrained by min_damage and max_damage. More...
 
bool mod_damage (int qty)
 same as other mod_damage, but uses DT_NULL as damage type. More...
 
bool inc_damage (damage_type dt)
 Increment item damage by itype::damage_scale constrained by max_damage. More...
 
bool inc_damage ()
 same as other inc_damage, but uses DT_NULL as damage type. More...
 
nc_color damage_color () const
 Provide color for UI display dependent upon current item damage level. More...
 
std::string damage_symbol () const
 Provide prefix symbol for UI display dependent upon current item damage level. More...
 
std::string durability_indicator (bool include_intact=false) const
 Provides a prefix for the durability state of the item. More...
 
const std::set< itype_id > & repaired_with () const
 If possible to repair this item what tools could potentially be used for this purpose? More...
 
bool already_used_by_player (const player &p) const
 Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player. More...
 
void mark_as_used_by_player (const player &p)
 Marks the item as being used by this specific player, it remains unmarked for other players. More...
 
bool is_filthy () const
 Marks the item as filthy, so characters with squeamish trait can't wear it. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
 This is called once each turn. More...
 
bool process (player *carrier, const tripoint &pos, bool activate, temperature_flag flag, const weather_manager &weather_generator)
 
std::optional< tripointget_cable_target (Character *p, const tripoint &pos) const
 Gets the point (vehicle tile) the cable is connected to. More...
 
void reset_cable (player *p)
 Helper to bring a cable back to its initial state. More...
 
bool needs_processing () const
 Whether the item should be processed (by calling process). More...
 
int processing_speed () const
 The rate at which an item should be processed, in number of turns between updates. More...
 
void process_artifact (player *carrier, const tripoint &pos)
 Process and apply artifact effects. More...
 
void process_relic (Character &carrier)
 
bool destroyed_at_zero_charges () const
 
bool is_null () const
 
bool is_comestible () const
 
bool is_food () const
 
bool is_food_container () const
 
bool is_med_container () const
 
bool is_ammo_container () const
 
bool is_medication () const
 
bool is_bionic () const
 
bool is_magazine () const
 
bool is_battery () const
 
bool is_ammo_belt () const
 
bool is_bandolier () const
 
bool is_holster () const
 
bool is_ammo () const
 
bool is_pet_armor (bool on_pet=false) const
 
bool is_armor () const
 
bool is_book () const
 
bool is_map () const
 
bool is_salvageable () const
 
bool is_craft () const
 
bool is_deployable () const
 
bool is_tool () const
 
bool is_transformable () const
 
bool is_artifact () const
 
bool is_relic () const
 
bool is_bucket () const
 
bool is_bucket_nonempty () const
 
bool is_brewable () const
 
bool is_engine () const
 
bool is_wheel () const
 
bool is_fuel () const
 
bool is_toolmod () const
 
bool is_faulty () const
 
bool is_irremovable () const
 
bool is_unarmed_weapon () const
 
itemget_food ()
 
const itemget_food () const
 
int wind_resist () const
 How resistant clothes made of this material are to wind (0-100) More...
 
std::set< fault_idfaults_potential () const
 What faults can potentially occur with this item? More...
 
int wheel_area () const
 Returns the total area of this wheel or 0 if it isn't one. More...
 
float fuel_energy () const
 Returns energy of one charge of this item as fuel for an engine. More...
 
std::string fuel_pump_terrain () const
 Returns the string of the id of the terrain that pumps this fuel, if any. More...
 
bool has_explosion_data () const
 
struct fuel_explosion get_explosion_data ()
 
bool can_contain (const item &it) const
 Can this item have given item/itype as content? More...
 
bool can_contain (const itype &tp) const
 
bool is_reloadable () const
 Is it ever possible to reload this item? Only the base item is considered with any mods ignored. More...
 
bool can_reload_with (const ammotype &ammo) const
 Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo. More...
 
bool can_reload_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo. More...
 
bool is_reloadable_with (const itype_id &ammo) const
 Returns true if this item can be reloaded with specified ammo type at this moment. More...
 
bool can_unload_liquid () const
 Returns true if not empty if it's liquid, it's not currently frozen in resealable container. More...
 
bool is_dangerous () const
 
bool is_tainted () const
 Is item derived from a zombie? More...
 
bool is_soft () const
 Is this item flexible enough to be worn on body parts like antlers? More...
 
bool has_effect_when_wielded (art_effect_passive effect) const
 Does the item provide the artifact effect when it is wielded? More...
 
bool has_effect_when_worn (art_effect_passive effect) const
 Does the item provide the artifact effect when it is worn? More...
 
bool has_effect_when_carried (art_effect_passive effect) const
 Does the item provide the artifact effect when it is carried? More...
 
void set_snippet (const snippet_id &id)
 Set the snippet text (description) of this specific item, using the snippet library. More...
 
bool operator< (const item &other) const
 
std::string components_to_string () const
 List of all components in printable form, empty if this item has no components. More...
 
uint64_t make_component_hash () const
 Creates a hash from the itype_ids of this item's components. More...
 
const itype_idtypeId () const
 return the unique identifier of the items underlying type More...
 
const itemget_contained () const
 Return a contained item (if any and only one). More...
 
bool spill_contents (Character &c)
 Unloads the item's contents. More...
 
bool spill_contents (const tripoint &pos)
 Unloads the item's contents. More...
 
bool can_holster (const item &obj, bool ignore=false) const
 Checks if item is a holster and currently capable of storing obj. More...
 
void on_wear (Character &p)
 Callback when a character starts wearing the item. More...
 
void on_takeoff (Character &p)
 Callback when a character takes off an item. More...
 
void on_wield (player &p, int mv=0)
 Callback when a player starts wielding the item. More...
 
void on_pickup (Character &p)
 Callback when a player starts carrying the item. More...
 
void on_contents_changed ()
 Callback when contents of the item are affected in any way other than just processing. More...
 
void on_damage (int qty, damage_type dt)
 Callback immediately before an item is damaged. More...
 
std::vector< trait_idmutations_from_wearing (const Character &guy) const
 
std::string type_name (unsigned int quantity=1) const
 Name of the item type (not the item), with proper plural. More...
 
int charges_per_volume (const units::volume &vol) const
 Number of (charges of) this item that fit into the given volume. More...
 
Item variables

Item variables can be used to store any value in the item.

The storage is persistent, it remains through saving & loading, it is copied when the item is moved etc. Each item variable is referred to by its name, so make sure you use a name that is not already used somewhere. You can directly store integer, floating point and string values. Data of other types must be converted to one of those to be stored. The set_var functions override the existing value. The get_var function return the value (if the variable exists), or the default value otherwise. The type of the default value determines which get_var function is used. All numeric values are returned as doubles and may be cast to the desired type. int v = itm.get_var("v", 0); // v will be an int double d = itm.get_var("v", 0.0); // d will be a double std::string s = itm.get_var("v", ""); // s will be a std::string // no default means empty string as default: auto n = itm.get_var("v"); // v will be a std::string

void set_var (const std::string &name, int value)
 
void set_var (const std::string &name, long long value)
 
void set_var (const std::string &name, long value)
 
void set_var (const std::string &name, double value)
 
double get_var (const std::string &name, double default_value) const
 
void set_var (const std::string &name, const tripoint &value)
 
tripoint get_var (const std::string &name, const tripoint &default_value) const
 
void set_var (const std::string &name, const std::string &value)
 
std::string get_var (const std::string &name, const std::string &default_value) const
 
std::string get_var (const std::string &name) const
 Get the variable, if it does not exists, returns an empty string. More...
 
bool has_var (const std::string &name) const
 Whether the variable is defined at all. More...
 
void erase_var (const std::string &name)
 Erase the value of the given variable. More...
 
void clear_vars ()
 Removes all item variables. More...
 
Item flags

If you use any new flags, add them to flags.json, add a comment to doc/JSON_FLAGS.md and make sure your new flag does not conflict with any existing flag.

Item flags are taken from the item type (itype::item_tags), but also from the item itself (item_tags). The item has the flag if it appears in either set.

Gun mods that are attached to guns also contribute their flags to the gun item.

bool has_flag (const std::string &flag) const
 
bool has_flag (const flag_str_id &flag) const
 
template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool has_any_flag (const Container &flags) const
 
bool has_own_flag (const std::string &flag) const
 Checks whether item itself has given flag (doesn't check item type or gunmods). More...
 
const FlagsSetTypeget_flags () const
 returs read-only set of flags of this item (not including flags from item type or gunmods) More...
 
itemset_flag (const std::string &flag)
 Idempotent filter setting an item specific flag. More...
 
itemunset_flag (const std::string &flag)
 Idempotent filter removing an item specific flag. More...
 
itemset_flag_recursive (const std::string &flag)
 Idempotent filter recursively setting an item specific flag on this item and its components. More...
 
void unset_flags ()
 Removes all item specific flags. More...
 
bool has_fault (const fault_id &fault) const
 Does this item have the specified fault. More...
 
Item properties

Properties are specific to an item type so unlike flags the meaning of a property may not be the same for two different item types.

Each item type can have multiple properties however duplicate property names are not permitted.

bool has_property (const std::string &prop) const
 
std::string get_property_string (const std::string &prop, const std::string &def="") const
 Get typed property for item. More...
 
int64_t get_property_int64_t (const std::string &prop, int64_t def=0) const
 
Light emitting items

Items can emit light either through the definition of their type (itype::light_emission) or through an item specific light data (light).

bool getlight (float &luminance, units::angle &width, units::angle &direction) const
 Directional light emission of the item. More...
 
int getlight_emit () const
 How much light (see lightmap.cpp) the item emits (it's assumed to be circular). More...
 
bool is_emissive () const
 Whether the item emits any light at all. More...
 
Seed data.
bool is_seed () const
 Whether this is actually a seed, the seed functions won't be of much use for non-seeds. More...
 
time_duration get_plant_epoch () const
 Time it takes to grow from one stage to another. More...
 
std::string get_plant_name () const
 The name of the plant as it appears in the various informational menus. More...
 
Armor related functions.

The functions here refer to values from islot_armor.

They only apply to armor items, those items can be worn. The functions are safe to call for any item, for non-armor they return a default value.

bool covers (body_part bp) const
 Whether this item (when worn) covers the given body part. More...
 
bool covers (const bodypart_id &bp) const
 
body_part_set get_covered_body_parts () const
 Bitset of all covered body parts. More...
 
body_part_set get_covered_body_parts (side s) const
 Bitset of all covered body parts, from a specific side. More...
 
bool is_sided () const
 Returns true if item is armor and can be worn on different sides of the body. More...
 
side get_side () const
 Returns side item currently worn on. More...
 
bool set_side (side s)
 Change the side on which the item is worn. More...
 
bool swap_side ()
 Swap the side on which the item is worn. More...
 
int get_warmth () const
 Returns the warmth value that this item has when worn. More...
 
int get_thickness () const
 Returns the islot_armor::thickness value, or 0 for non-armor. More...
 
layer_level get_layer () const
 Returns clothing layer for item. More...
 
int get_coverage () const
 Returns the relative coverage that this item has when worn. More...
 
int get_encumber_when_containing (const Character &, const units::volume &contents_volume) const
 Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents. More...
 
int get_encumber (const Character &) const
 Returns the encumbrance value that this item has when worn by given player. More...
 
units::volume get_storage () const
 Returns the storage amount (islot_armor::storage) that this item provides when worn. More...
 
float get_weight_capacity_modifier () const
 Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
units::mass get_weight_capacity_bonus () const
 Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn. More...
 
int get_env_resist (int override_base_resist=0) const
 Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn. More...
 
int get_base_env_resist_w_filter () const
 Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed. More...
 
bool is_power_armor () const
 Whether this is a power armor item. More...
 
const islot_armorfind_armor_data () const
 If this is an armor item, return its armor data. More...
 
bool is_worn_only_with (const item &it) const
 Returns true whether this item can be worn only when. More...
 
Pet armor related functions.

The functions here refer to values from islot_pet_armor.

They only apply to pet armor items, those items can be worn by pets. The functions are safe to call for any item, for non-pet armor they return a default value.

units::volume get_pet_armor_max_vol () const
 
units::volume get_pet_armor_min_vol () const
 
bodytype_id get_pet_armor_bodytype () const
 
Books

Book specific functions, apply to items that are books.

int get_chapters () const
 How many chapters the book has (if any). More...
 
int get_remaining_chapters (const Character &ch) const
 Get the number of unread chapters. More...
 
void mark_chapter_as_read (const Character &ch)
 Mark one chapter of the book as read by the given player. More...
 
std::vector< std::pair< const recipe *, int > > get_available_recipes (const player &u) const
 Enumerates recipes available from this book and the skill level required to use them. More...
 
Martial art techniques

See martialarts.h for further info.

bool has_technique (const matec_id &tech) const
 Whether the item supports a specific martial art technique (either through its type, or through its individual techniques). More...
 
std::set< matec_idget_techniques () const
 Returns all the martial art techniques that this items supports. More...
 
void add_technique (const matec_id &tech)
 Add the given technique to the item specific techniques. More...
 
std::vector< item * > toolmods ()
 Returns all toolmods currently attached to this item (always empty if item not a tool) More...
 
std::vector< const item * > toolmods () const
 
Gun and gunmod functions

Gun and gun mod functions.

Anything stated to apply to guns, applies to auxiliary gunmods as well (they are some kind of gun). Non-guns are items that are neither gun nor auxiliary gunmod.

bool is_gunmod () const
 
bool is_gun () const
 Can this item be used to perform a ranged attack? More...
 
units::energy energy_remaining () const
 Quantity of energy currently loaded in tool or battery. More...
 
int ammo_remaining () const
 Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod. More...
 
int ammo_capacity () const
 Maximum quantity of ammunition loadable for tool, gun or auxiliary gunmod. More...
 
int ammo_capacity (bool potential_capacity) const
 
int ammo_required () const
 Quantity of ammunition consumed per usage of tool or with each shot of gun. More...
 
bool ammo_sufficient (int qty=1) const
 Check if sufficient ammo is loaded for given number of uses. More...
 
int ammo_consume (int qty, const tripoint &pos)
 Consume ammo (if available) and return the amount of ammo that was consumed. More...
 
const itypeammo_data () const
 Specific ammo data, returns nullptr if item is neither ammo nor loaded with any. More...
 
itype_id ammo_current () const
 Specific ammo type, returns "null" if item is neither ammo nor loaded with any. More...
 
const std::set< ammotype > & ammo_types (bool conversion=true) const
 Set of ammo types (ammunition_type) used by item. More...
 
ammotype ammo_type () const
 Ammo type of an ammo item. More...
 
itype_id ammo_default (bool conversion=true) const
 Get default ammo used by item or a null id if item does not have a default ammo type. More...
 
itype_id common_ammo_default (bool conversion=true) const
 Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists. More...
 
std::set< ammo_effect_str_idammo_effects (bool with_ammo=true) const
 Get ammo effects for item optionally inclusive of any resulting from the loaded ammo. More...
 
std::string ammo_sort_name () const
 
int casings_count () const
 How many spent casings are contained within this item? More...
 
void casings_handle (const std::function< bool(item &)> &func)
 Apply predicate to each contained spent casing removing it if predicate returns true. More...
 
bool magazine_integral () const
 Does item have an integral magazine (as opposed to allowing detachable magazines) More...
 
itype_id magazine_default (bool conversion=true) const
 Get the default magazine type (if any) for the current effective ammo type. More...
 
std::set< itype_idmagazine_compatible (bool conversion=true) const
 Get compatible magazines (if any) for this item. More...
 
itemmagazine_current ()
 Currently loaded magazine (if any) More...
 
const itemmagazine_current () const
 
std::vector< item * > gunmods ()
 Returns all gunmods currently attached to this item (always empty if item not a gun) More...
 
std::vector< const item * > gunmods () const
 
itemgunmod_find (const itype_id &mod)
 Get first attached gunmod matching type or nullptr if no such mod or item is not a gun. More...
 
const itemgunmod_find (const itype_id &mod) const
 
ret_val< bool > is_gunmod_compatible (const item &mod) const
 
std::map< gun_mode_id, gun_modegun_all_modes () const
 Get all possible modes for this gun inclusive of any attached gunmods. More...
 
gun_mode gun_get_mode (const gun_mode_id &mode) const
 Check if gun supports a specific mode returning an invalid/empty mode if not. More...
 
gun_mode gun_current_mode () const
 Get the current mode for this gun (or an invalid mode if item is not a gun) More...
 
gun_mode_id gun_get_mode_id () const
 Get id of mode a gun is currently set to, e.g. More...
 
bool gun_set_mode (const gun_mode_id &mode)
 Try to set the mode for a gun, returning false if no such mode is possible. More...
 
void gun_cycle_mode ()
 Switch to the next available firing mode. More...
 
int sight_dispersion () const
 Get lowest dispersion of either integral or any attached sights. More...
 
sound_data gun_noise (bool burst=false) const
 Returns the sound of the gun being fired. More...
 
bool is_silent () const
 Whether this is a (nearly) silent gun (a tiny bit of sound is allowed). More...
 
int gun_range (const player *p) const
 The weapons range in map squares. More...
 
int gun_range (bool with_ammo=true) const
 Summed range value of a gun, including values from mods. More...
 
double gun_recoil_multiplier (bool bipod=false) const
 Get multiplier on recoil considering handling and attached gunmods. More...
 
int gun_recoil (bool bipod=false) const
 Get effective recoil considering handling, loaded ammo and effects of attached gunmods. More...
 
damage_instance gun_damage (bool with_ammo=true) const
 Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods. More...
 
int gun_dispersion (bool with_ammo=true, bool with_scaling=true) const
 Summed dispersion of a gun, including values from mods. More...
 
skill_id gun_skill () const
 The skill used to operate the gun. More...
 
gun_type_type gun_type () const
 Get the type of a ranged weapon (e.g. More...
 
std::map< gunmod_location, int > get_mod_locations () const
 Get mod locations, including those added by other mods. More...
 
int get_free_mod_locations (const gunmod_location &location) const
 Number of mods that can still be installed into the given mod location, for non-guns it always returns 0. More...
 
bool is_firearm () const
 Does it require gunsmithing tools to repair. More...
 
int get_reload_time () const
 Returns the reload time of the gun. More...
 
Vehicle parts
int engine_displacement () const
 for combustion engines the displacement (cc) More...
 
- Public Member Functions inherited from visitable< item >
VisitResponse visit_items (const std::function< VisitResponse(item *, item *)> &func)
 Traverses this object and any child items contained using a visitor pattern. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *, const item *)> &func) const
 
VisitResponse visit_items (const std::function< VisitResponse(item *)> &func)
 Lightweight version which provides only the current node. More...
 
VisitResponse visit_items (const std::function< VisitResponse(const item *)> &func) const
 
itemfind_parent (const item &it)
 Determine the immediate parent container (if any) for an item. More...
 
const itemfind_parent (const item &it) const
 
std::vector< item * > parents (const item &it)
 Returns vector of parent containers (if any) starting with the innermost. More...
 
std::vector< const item * > parents (const item &it) const
 
bool has_item (const item &it) const
 Returns true if this visitable instance contains the item. More...
 
bool has_item_with (const std::function< bool(const item &)> &filter) const
 Returns true if any item (including those within a container) matches the filter. More...
 
bool has_quality (const quality_id &qual, int level=1, int qty=1) const
 Returns true if instance has amount (or more) items of at least quality level. More...
 
int max_quality (const quality_id &qual) const
 Return maximum tool quality level provided by instance or INT_MIN if not found. More...
 
int charges_of (const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
 Count maximum available charges from this instance and any contained items. More...
 
int amount_of (const itype_id &what, bool pseudo=true, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >) const
 Count items matching id including both this instance and any contained items. More...
 
bool has_amount (const itype_id &what, int qty, bool pseudo=true, const std::function< bool(const item &)> &filter=return_true< item >) const
 Check instance provides at least qty of an item (. More...
 
std::vector< item * > items_with (const std::function< bool(const item &)> &filter)
 Returns all items (including those within a container) matching the filter. More...
 
std::vector< const item * > items_with (const std::function< bool(const item &)> &filter) const
 
std::list< itemremove_items_with (const std::function< bool(const item &)> &filter, int count=INT_MAX)
 Removes items contained by this instance which match the filter. More...
 
item remove_item (item &it)
 Removes and returns the item which must be contained by this instance. More...
 

Static Public Member Functions

static item make_corpse (const mtype_id &mt=string_id< mtype >::NULL_ID(), time_point turn=calendar::turn, const std::string &name="", int upgrade_time=-1)
 Make a corpse of the given monster type. More...
 

Bionics / CBMs

Functions specific to CBMs

enum class  sizing {
  human_sized_human_char = 0 , big_sized_human_char , small_sized_human_char , big_sized_big_char ,
  human_sized_big_char , small_sized_big_char , small_sized_small_char , human_sized_small_char ,
  big_sized_small_char , not_wearable
}
 
static const int INFINITE_CHARGES = INT_MAX
 
const itypetype
 
item_contents contents
 
std::list< itemcomponents
 
std::set< fault_idfaults
 What faults (if any) currently apply to this item. More...
 
FlagsSetType item_tags
 
int charges
 
units::energy energy
 
int recipe_charges = 1
 
int burnt = 0
 
int poison = 0
 
int frequency = 0
 
snippet_id snip_id = snippet_id::NULL_ID()
 
int irradiation = 0
 
int item_counter = 0
 
int mission_id = -1
 
int player_id = -1
 
bool encumbrance_update_ = false
 
char invlet = 0
 
bool active = false
 
safe_reference< Characteractivated_by
 
bool is_favorite = false
 
pimpl< item_drop_tokendrop_token
 Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class. More...
 
safe_reference_anchor anchor
 
const itypecurammo = nullptr
 
std::map< std::string, std::string > item_vars
 
const mtypecorpse = nullptr
 
std::string corpse_name
 
std::set< matec_idtechniques
 
cata::value_ptr< craft_datacraft_data_
 
cata::value_ptr< relicrelic_data
 
time_duration rot = 0_turns
 Accumulated rot, expressed as time the item has been in standard temperature. More...
 
time_point last_rot_check = calendar::turn_zero
 Time when the rot calculation was last performed. More...
 
time_point bday
 The time the item was created. More...
 
faction_id owner = faction_id::NULL_ID()
 
faction_id old_owner = faction_id::NULL_ID()
 
int damage_ = 0
 
light_emission light = nolight
 
bool is_upgrade () const
 Whether the CBM is an upgrade to another bionic module. More...
 
bool has_use () const
 Returns true if the item has any use function. More...
 
const use_functionget_use (const std::string &use_name) const
 Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents. More...
 
itemget_usable_item (const std::string &use_name)
 Checks this item and its contents (recursively) for types that have use_function with type use_name. More...
 
int units_remaining (const Character &ch, int limit=INT_MAX) const
 How many units (ammo or charges) are remaining? More...
 
bool units_sufficient (const Character &ch, int qty=-1) const
 Check if item has sufficient units (ammo or charges) remaining. More...
 
std::string get_corpse_name ()
 Returns name of deceased being if it had any or empty string if not. More...
 
bool has_label () const
 Returns true if item has "item_label" itemvar. More...
 
std::string label (unsigned int quantity=0) const
 Returns label from "item_label" itemvar and quantity. More...
 
bool has_infinite_charges () const
 
skill_id contextualize_skill (const skill_id &id) const
 Puts the skill in context of the item. More...
 
bool release_monster (const tripoint &target, int radius=0)
 
int contain_monster (const tripoint &target)
 
time_duration age () const
 
void set_age (const time_duration &age)
 
void legacy_fast_forward_time ()
 
time_point birthday () const
 
void set_birthday (const time_point &bday)
 
void handle_pickup_ownership (Character &c)
 
int get_gun_ups_drain () const
 
void validate_ownership () const
 
void set_old_owner (const faction_id &temp_owner)
 
void remove_old_owner () const
 
void set_owner (const faction_id &new_owner)
 
void set_owner (const Character &c)
 
void remove_owner () const
 
faction_id get_owner () const
 
faction_id get_old_owner () const
 
bool is_owned_by (const Character &c, bool available_to_take=false) const
 
bool is_old_owner (const Character &c, bool available_to_take=false) const
 
std::string get_owner_name () const
 
int get_min_str () const
 
const cata::value_ptr< islot_comestible > & get_comestible () const
 
const recipeget_making () const
 Get the stored recipe for in progress crafts. More...
 
int get_next_failure_point () const
 Get the failure point stored in this item. More...
 
void set_next_failure_point (const player &crafter)
 Calculates and sets the next failure point for an in progress craft. More...
 
bool handle_craft_failure (player &crafter)
 Handle failure during crafting. More...
 
requirement_data get_continue_reqs () const
 Returns requirement data representing what is needed to resume work on an in progress craft. More...
 
void inherit_flags (const item &parent, const recipe &making)
 Inherit applicable flags from the given parent item. More...
 
void inherit_flags (const std::list< item > &parents, const recipe &making)
 Inherit applicable flags from the given list of parent items. More...
 
void set_tools_to_continue (bool value)
 
bool has_tools_to_continue () const
 
void set_cached_tool_selections (const std::vector< comp_selection< tool_comp > > &selections)
 
const std::vector< comp_selection< tool_comp > > & get_cached_tool_selections () const
 
const std::vector< enchantment > & get_enchantments () const
 
double bonus_from_enchantments (const Character &owner, double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only. More...
 
double bonus_from_enchantments_wielded (double base, enchant_vals::mod value, bool round=false) const
 Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied. More...
 
const std::vector< relic_recharge > & get_relic_recharge_scheme () const
 
sizing get_sizing (const Character &, bool) const
 
void set_favorite (bool favorite)
 
bool has_clothing_mod () const
 
float get_clothing_mod_val (clothing_mod_type type) const
 
void update_clothing_mod_val ()
 
static std::string nname (const itype_id &id, unsigned int quantity=1)
 Returns the translated item name for the item with given id. More...
 
static bool count_by_charges (const itype_id &id)
 Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance. More...
 
bool use_amount_internal (const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
 
const use_functionget_use_internal (const std::string &use_name) const
 
bool process_internal (player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
 
bool is_reloadable_helper (const itype_id &ammo, bool now) const
 Helper for checking reloadability. More...
 
bool process_corpse (player *carrier, const tripoint &pos)
 
bool process_wet (player *carrier, const tripoint &pos)
 
bool process_litcig (player *carrier, const tripoint &pos)
 
bool process_extinguish (player *carrier, const tripoint &pos)
 
bool process_fake_smoke (player *carrier, const tripoint &pos)
 
bool process_fake_mill (player *carrier, const tripoint &pos)
 
bool process_cable (player *carrier, const tripoint &pos)
 
bool process_UPS (player *carrier, const tripoint &pos)
 
bool process_blackpowder_fouling (player *carrier)
 
bool process_tool (player *carrier, const tripoint &pos)
 

Additional Inherited Members

Detailed Description

Definition at line 210 of file item.h.

Member Typedef Documentation

◆ archive_type_tag

Definition at line 494 of file item.h.

◆ FlagsSetType

using item::FlagsSetType = cata::flat_set<std::string>

Definition at line 213 of file item.h.

Member Enumeration Documentation

◆ sizing

enum class item::sizing
strong
Enumerator
human_sized_human_char 
big_sized_human_char 
small_sized_human_char 
big_sized_big_char 
human_sized_big_char 
small_sized_big_char 
small_sized_small_char 
human_sized_small_char 
big_sized_small_char 
not_wearable 

Definition at line 2130 of file item.h.

2130 {
2131 human_sized_human_char = 0,
2132 big_sized_human_char,
2133 small_sized_human_char,
2134 big_sized_big_char,
2135 human_sized_big_char,
2136 small_sized_big_char,
2137 small_sized_small_char,
2138 human_sized_small_char,
2139 big_sized_small_char,
2140 not_wearable
2141 };

Constructor & Destructor Documentation

◆ item() [1/11]

item::item ( )

Definition at line 368 of file item.cpp.

369{
370 type = nullitem();
371 charges = 0;
372}
time_point bday
The time the item was created.
Definition: item.h:2231
int charges
Definition: item.h:2203
const itype * type
Definition: item.h:2164
static const itype * nullitem()
Definition: item.cpp:319
const time_point & start_of_cataclysm
Definition: calendar.cpp:33

References charges, nullitem(), and type.

Referenced by add_rain_to_container(), ammo_set(), vehicle_part::deserialize(), io(), item(), and split().

◆ item() [2/11]

item::item ( item &&  )
default

◆ item() [3/11]

item::item ( const item )
default

◆ item() [4/11]

item::item ( const itype_id id,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 434 of file item.cpp.

435 : item( & * id, turn, qty ) {}
item()
Definition: item.cpp:368
time_point turn
Definition: calendar.cpp:36

◆ item() [5/11]

item::item ( const itype type,
time_point  turn = calendar::turn,
int  qty = -1 
)
explicit

Definition at line 374 of file item.cpp.

374 : type( type ), bday( turn )
375{
376 corpse = has_flag( flag_CORPSE ) ? &mtype_id::NULL_ID().obj() : nullptr;
378
379 if( qty >= 0 ) {
380 charges = qty;
381 } else {
382 if( type->tool && type->tool->rand_charges.size() > 1 ) {
383 const int charge_roll = rng( 1, type->tool->rand_charges.size() - 1 );
384 charges = rng( type->tool->rand_charges[charge_roll - 1], type->tool->rand_charges[charge_roll] );
385 } else {
387 }
388 }
389
391 itype_id nanofab_recipe = item_group::item_from( item_group_id( "nanofab_recipes" ) ).typeId();
392 set_var( "NANOFAB_ITEM_ID", nanofab_recipe.str() );
393 }
394
395 if( type->gun ) {
396 for( const itype_id &mod : type->gun->built_in_mods ) {
397 item it( mod, turn, qty );
398 it.set_flag( "IRREMOVABLE" );
399 put_in( it );
400 }
401 for( const itype_id &mod : type->gun->default_mods ) {
402 put_in( item( mod, turn, qty ) );
403 }
404
405 } else if( type->magazine ) {
406 if( type->magazine->count > 0 ) {
407 put_in( item( type->magazine->default_ammo, calendar::turn, type->magazine->count ) );
408 }
409
410 } else if( goes_bad() ) {
411 active = true;
413
414 } else if( type->tool ) {
415 if( ammo_remaining() && !ammo_types().empty() ) {
417 }
418 }
419
420 if( ( type->gun || type->tool ) && !magazine_integral() ) {
421 set_var( "magazine_converted", 1 );
422 }
423
424 if( !type->snippet_category.empty() ) {
426 }
427
428 // item always has any relic properties from itype.
429 if( type->relic_data ) {
431 }
432}
units::quantity< V, B > rng(const units::quantity< V, B > &min, const units::quantity< V, B > &max)
Definition: artifact.cpp:32
Definition: item.h:211
int ammo_remaining() const
Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.
Definition: item.cpp:7395
bool active
Definition: item.h:2241
void put_in(const item &payload)
Puts the given item into this one, no checks are performed.
Definition: item.cpp:998
void set_var(const std::string &name, int value)
Definition: item.cpp:1003
item & ammo_set(const itype_id &ammo, int qty=-1)
Filter setting the ammo for this instance Any existing ammo is removed.
Definition: item.cpp:593
bool goes_bad() const
whether an item is perishable (can rot)
Definition: item.cpp:5506
const mtype * corpse
Definition: item.h:2176
snippet_id snip_id
Definition: item.h:2210
const itype_id & typeId() const
return the unique identifier of the items underlying type
Definition: item.cpp:8366
bool magazine_integral() const
Does item have an integral magazine (as opposed to allowing detachable magazines)
Definition: item.cpp:7673
bool has_flag(const std::string &flag) const
Definition: item.cpp:5311
itype_id ammo_default(bool conversion=true) const
Get default ammo used by item or a null id if item does not have a default ammo type.
Definition: item.cpp:7609
time_point last_rot_check
Time when the rot calculation was last performed.
Definition: item.h:2229
const std::set< ammotype > & ammo_types(bool conversion=true) const
Set of ammo types (ammunition_type) used by item.
Definition: item.cpp:7578
int item_counter
Definition: item.h:2212
cata::value_ptr< relic > relic_data
Definition: item.h:2201
snippet_id random_id_from_category(const std::string &cat) const
Returns the id of a random snippet out of the given category.
const T & obj() const
Returns the actual object this id refers to.
Definition: achievement.cpp:60
const std::string & str() const
Returns the identifier as plain std::string.
Definition: string_id.h:255
static const string_id< mtype > & NULL_ID()
Returns a null id whose string_id<T>::is_null() must always return true.
static const std::string flag_NANOFAB_TEMPLATE("NANOFAB_TEMPLATE")
static const std::string flag_CORPSE("CORPSE")
item item_from(const item_group_id &group_id, const time_point &birthday)
Returns a random item from the item group, handles packaged food by putting it into its container and...
Definition: item_group.cpp:589
std::string snippet_category
Definition: itype.h:907
cata::value_ptr< islot_gun > gun
Definition: itype.h:859
cata::value_ptr< islot_tool > tool
Definition: itype.h:849
int charges_default() const
Definition: itype.cpp:98
cata::value_ptr< relic > relic_data
Definition: itype.h:867
cata::value_ptr< islot_magazine > magazine
Definition: itype.h:861
int countdown_interval
Default countdown interval (if any) for item.
Definition: itype.h:953
snippet_library SNIPPET
string_id< Item_group > item_group_id
Definition: type_id.h:77

References active, ammo_default(), ammo_remaining(), ammo_set(), ammo_types(), bday, charges, itype::charges_default(), corpse, itype::countdown_interval, flag_CORPSE(), flag_NANOFAB_TEMPLATE(), goes_bad(), itype::gun, has_flag(), item(), item_counter, item_group::item_from(), last_rot_check, itype::magazine, magazine_integral(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), put_in(), snippet_library::random_id_from_category(), relic_data, itype::relic_data, rng(), set_flag(), set_var(), snip_id, SNIPPET, itype::snippet_category, string_id< T >::str(), itype::tool, calendar::turn, type, and typeId().

◆ item() [6/11]

item::item ( const itype_id id,
time_point  turn,
default_charges_tag  tag 
)

Definition at line 440 of file item.cpp.

441 : item( & * id, turn, tag ) {}

◆ item() [7/11]

item::item ( const itype type,
time_point  turn,
default_charges_tag   
)

Definition at line 437 of file item.cpp.

438 : item( type, turn, type->charges_default() ) {}

◆ item() [8/11]

item::item ( const itype_id id,
time_point  turn,
solitary_tag  tag 
)

Definition at line 446 of file item.cpp.

447 : item( & * id, turn, tag ) {}

◆ item() [9/11]

item::item ( const itype type,
time_point  turn,
solitary_tag   
)

Definition at line 443 of file item.cpp.

444 : item( type, turn, type->count_by_charges() ? 1 : -1 ) {}
bool count_by_charges() const
Definition: itype.cpp:93

◆ item() [10/11]

item::item ( const recipe rec,
int  qty,
std::list< item items,
std::vector< item_comp selections 
)

For constructing in-progress crafts.

Definition at line 467 of file item.cpp.

468 : item( "craft", calendar::turn, qty )
469{
470 craft_data_ = cata::make_value<craft_data>();
471 craft_data_->making = rec;
472 components = items;
473 craft_data_->comps_used = selections;
474
475 if( is_food() ) {
476 active = true;
478 if( goes_bad() ) {
479 const item *most_rotten = get_most_rotten_component( *this );
480 if( most_rotten ) {
481 set_relative_rot( most_rotten->get_relative_rot() );
482 }
483 }
484 }
485
486 for( item &component : components ) {
487 for( const std::string &f : component.item_tags ) {
488 if( json_flag::get( f ).craft_inherit() ) {
489 set_flag( f );
490 }
491 }
492 for( const std::string &f : component.type->get_flags() ) {
493 if( json_flag::get( f ).craft_inherit() ) {
494 set_flag( f );
495 }
496 }
497 }
498 // this extra section is so that in-progress crafts will correctly display expected flags.
499 for( const std::string &flag : rec->flags_to_delete ) {
500 unset_flag( flag );
501 }
502}
cata::value_ptr< craft_data > craft_data_
Definition: item.h:2198
std::list< item > components
Definition: item.h:2166
bool is_food() const
Definition: item.cpp:6600
item & set_flag(const std::string &flag)
Idempotent filter setting an item specific flag.
Definition: item.cpp:5340
item & unset_flag(const std::string &flag)
Idempotent filter removing an item specific flag.
Definition: item.cpp:5346
void set_relative_rot(double val)
Set current item rot relative to shelf life (no-op if item does not spoil)
Definition: item.cpp:5547
double get_relative_rot() const
Get rot value relative to shelf life (or 0 if item does not spoil)
Definition: item.cpp:5539
static const json_flag & get(const std::string &id)
Fetches flag definition (or null flag if not found)
Definition: flag.cpp:70
std::set< std::string > flags_to_delete
Definition: recipe.h:115
static const item * get_most_rotten_component(const item &craft)
Definition: item.cpp:454
itype_id type
Definition: requirements.h:58
const FlagsSetType & get_flags() const
Definition: itype.cpp:156

References active, bday, components, craft_data_, recipe::flags_to_delete, json_flag::get(), itype::get_flags(), get_most_rotten_component(), get_relative_rot(), goes_bad(), is_food(), last_rot_check, set_flag(), set_relative_rot(), component::type, and unset_flag().

◆ item() [11/11]

template<typename... Args>
item::item ( const std::string &  itype,
Args &&...  args 
)
inline

Definition at line 241 of file item.h.

241 :
242 item( itype_id( itype ), std::forward<Args>( args )... )
243 {}
Definition: itype.h:836

◆ ~item()

item::~item ( )
default

Member Function Documentation

◆ acid_resist()

int item::acid_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Resistance against different damage types (damage_type).

Larger values means more resistance are thereby better, but there is no absolute value to compare them to. The values can be interpreted as chance (one_in) of damaging the item when exposed to the type of damage.

Parameters
to_selfIf this is true, it returns item's own resistance, not one it gives to wearer.
base_env_resistWill override the base environmental resistance (to allow hypothetical calculations for gas masks).

Definition at line 6135 of file item.cpp.

6136{
6137 if( to_self ) {
6138 // Currently no items are damaged by acid
6139 return INT_MAX;
6140 }
6141
6142 float resist = 0.0;
6144 if( is_null() ) {
6145 return 0.0;
6146 }
6147
6148 const std::vector<const material_type *> mat_types = made_of_types();
6149 if( !mat_types.empty() ) {
6150 // Not sure why cut and bash get an armor thickness bonus but acid doesn't,
6151 // but such is the way of the code.
6152
6153 for( const material_type *mat : mat_types ) {
6154 resist += mat->acid_resist();
6155 }
6156 // Average based on number of materials.
6157 resist /= mat_types.size();
6158 }
6159
6160 const int env = get_env_resist( base_env_resist );
6161 if( env < 10 ) {
6162 // Low env protection means it doesn't prevent acid seeping in.
6163 resist *= env / 10.0f;
6164 }
6165
6166 return std::lround( resist + mod );
6167}
float get_clothing_mod_val(clothing_mod_type type) const
Definition: item.cpp:10164
bool is_null() const
Definition: item.cpp:735
std::vector< const material_type * > made_of_types() const
Same as made_of(), but returns the material_type directly.
Definition: item.cpp:6434
int get_env_resist(int override_base_resist=0) const
Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides whe...
Definition: item.cpp:5771
@ clothing_mod_type_acid
Definition: clothing_mod.h:17

References clothing_mod_type_acid, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ activate()

item & item::activate ( )

Filter converting instance to active state.

Definition at line 560 of file item.cpp.

561{
562 if( active ) {
563 return *this; // no-op
564 }
565
566 if( type->countdown_interval > 0 ) {
568 }
569
570 active = true;
571
572 return *this;
573}

References active, itype::countdown_interval, item_counter, and type.

Referenced by iuse::cable_attach(), make_gun_projectile(), process(), and process_internal().

◆ actualize_rot()

bool item::actualize_rot ( const tripoint pnt,
temperature_flag  temperature,
const weather_manager weather 
)

Whether the item has to be removed as it has rotten away completely.

May change the item as it calls process_rot()

Parameters
pntThe position of the item on the current map.
temperatureFlag for special locations that affect temperature.
weatherWeather manager to supply temperature.
Returns
true if the item has rotten away and should be removed, false otherwise.

Definition at line 8812 of file item.cpp.

8814{
8815 if( goes_bad() ) {
8816 return process_rot( false, pnt, nullptr, temperature, weather );
8817 } else if( type->container && type->container->preserves ) {
8818 // Containers like tin cans preserves all items inside, they do not rot at all.
8819 return false;
8820 } else if( type->container && type->container->seals ) {
8821 // Items inside rot but do not vanish as the container seals them in.
8822 for( item *c : contents.all_items_top() ) {
8823 if( c->goes_bad() ) {
8824 c->process_rot( true, pnt, nullptr, temperature, weather );
8825 }
8826 }
8827 return false;
8828 } else {
8829 std::vector<item *> removed_items;
8830 // Check and remove rotten contents, but always keep the container.
8831 for( item *it : contents.all_items_top() ) {
8832 if( it->actualize_rot( pnt, temperature, weather ) ) {
8833 removed_items.push_back( it );
8834 }
8835 }
8836 for( item *it : removed_items ) {
8837 remove_item( *it );
8838 }
8839
8840 return false;
8841 }
8842}
std::list< item * > all_items_top()
returns a list of pointers to all top-level items
item_contents contents
Definition: item.h:2165
bool process_rot(const tripoint &pos)
Update temperature for things like food Update rot for things that perish All items that rot also hav...
Definition: item.cpp:8959
item remove_item(item &it)
Removes and returns the item which must be contained by this instance.
Definition: visitable.cpp:564
constexpr double c
Definition: magic.cpp:1032
quantity< int, temperature_in_millidegree_celsius_tag > temperature
cata::value_ptr< islot_container > container
Slots for various item type properties.
Definition: itype.h:848

References item_contents::all_items_top(), c, itype::container, contents, goes_bad(), process_rot(), visitable< item >::remove_item(), and type.

◆ add_technique()

void item::add_technique ( const matec_id tech)

Add the given technique to the item specific techniques.

Note that other items of the same type are not affected by this.

Definition at line 5452 of file item.cpp.

5453{
5454 techniques.insert( tech );
5455}
std::set< matec_id > techniques
Definition: item.h:2178

References techniques.

Referenced by mdeath::jabberwock().

◆ age()

◆ allow_crafting_component()

bool item::allow_crafting_component ( ) const

Permits filthy components, should only be used as a helper in creating filters.

Definition at line 8546 of file item.cpp.

8547{
8548 if( is_toolmod() && is_irremovable() ) {
8549 return false;
8550 }
8551
8552 // vehicle batteries are implemented as magazines of charge
8553 if( is_magazine() && ammo_types().count( ammo_battery ) ) {
8554 return true;
8555 }
8556
8557 // fixes #18886 - turret installation may require items with irremovable mods
8558 if( is_gun() ) {
8559 bool valid = true;
8560 visit_items( [&]( const item * it ) {
8561 if( this == it ) {
8562 return VisitResponse::NEXT;
8563 }
8564 if( !( it->is_magazine() || ( it->is_gunmod() && it->is_irremovable() ) ) ) {
8565 valid = false;
8566 return VisitResponse::ABORT;
8567 }
8568 return VisitResponse::NEXT;
8569 } );
8570 return valid;
8571 }
8572
8573 return contents.empty();
8574}
bool empty() const
int count() const
If count_by_charges(), returns charges, otherwise 1.
Definition: item.cpp:6018
bool is_irremovable() const
Definition: item.cpp:6783
bool is_gun() const
Can this item be used to perform a ranged attack?
Definition: item.cpp:6525
bool is_toolmod() const
Definition: item.cpp:6773
bool is_gunmod() const
Definition: item.cpp:6555
bool is_magazine() const
Definition: item.cpp:6565
VisitResponse visit_items(const std::function< VisitResponse(item *, item *)> &func)
Traverses this object and any child items contained using a visitor pattern.
Definition: visitable.cpp:422
static const ammotype ammo_battery("battery")

References ammo_battery, ammo_types(), contents, count(), item_contents::empty(), is_gun(), is_gunmod(), is_irremovable(), is_magazine(), is_toolmod(), NEXT, and visitable< item >::visit_items().

◆ already_used_by_player()

bool item::already_used_by_player ( const player p) const

Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific player.

Definition at line 8861 of file item.cpp.

8862{
8863 const auto it = item_vars.find( USED_BY_IDS );
8864 if( it == item_vars.end() ) {
8865 return false;
8866 }
8867 // USED_BY_IDS always starts *and* ends with a ';', the search string
8868 // ';<id>;' matches at most one part of USED_BY_IDS, and only when exactly that
8869 // id has been added.
8870 const std::string needle = string_format( ";%d;", p.getID().get_value() );
8871 return it->second.find( needle ) != std::string::npos;
8872}
character_id getID() const
Definition: character.cpp:492
int get_value() const
Definition: character_id.h:23
std::map< std::string, std::string > item_vars
Definition: item.h:2175
static const std::string USED_BY_IDS("USED_BY_IDS")
std::string string_format(std::string_view format, Args &&...args)
Simple wrapper over string_formatter::parse.

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by tname(), and reveal_map_actor::use().

◆ ammo_capacity() [1/2]

◆ ammo_capacity() [2/2]

int item::ammo_capacity ( bool  potential_capacity) const
Parameters
potential_capacitywhether to try a default magazine if necessary

Definition at line 7427 of file item.cpp.

7428{
7429 int res = 0;
7430
7431 const item *mag = magazine_current();
7432 if( mag ) {
7433 return mag->ammo_capacity();
7434 }
7435
7436 if( is_tool() ) {
7437 res = type->tool->max_charges;
7438 if( res == 0 && magazine_default() && potential_capacity ) {
7439 res = magazine_default()->magazine->capacity;
7440 }
7441 for( const item *e : toolmods() ) {
7442 res *= e->type->mod->capacity_multiplier;
7443 }
7444 }
7445
7446 if( is_gun() ) {
7447 res = type->gun->clip;
7448 for( const item *e : gunmods() ) {
7449 res *= e->type->mod->capacity_multiplier;
7450 }
7451 }
7452
7453 if( is_magazine() ) {
7454 res = type->magazine->capacity;
7455 }
7456
7457 if( is_bandolier() ) {
7458 return dynamic_cast<const bandolier_actor *>
7459 ( type->get_use( "bandolier" )->get_actor_ptr() )->capacity;
7460 }
7461
7462 return res;
7463}
Store ammo and later reload using it.
Definition: iuse_actor.h:884
std::vector< item * > toolmods()
Returns all toolmods currently attached to this item (always empty if item not a tool)
Definition: item.cpp:5457
bool is_tool() const
Definition: item.cpp:6966
itype_id magazine_default(bool conversion=true) const
Get the default magazine type (if any) for the current effective ammo type.
Definition: item.cpp:7688
bool is_bandolier() const
Definition: item.cpp:6580
item * magazine_current()
Currently loaded magazine (if any)
Definition: item.cpp:7735
std::vector< item * > gunmods()
Returns all gunmods currently attached to this item (always empty if item not a gun)
Definition: item.cpp:7748
const use_function * get_use(const std::string &iuse_name) const
Definition: itype.cpp:166
iuse_actor * get_actor_ptr()
Definition: iuse.h:315

References ammo_capacity(), use_function::get_actor_ptr(), itype::get_use(), itype::gun, gunmods(), is_bandolier(), is_gun(), is_magazine(), is_tool(), itype::magazine, magazine_current(), magazine_default(), itype::tool, toolmods(), and type.

◆ ammo_consume()

int item::ammo_consume ( int  qty,
const tripoint pos 
)

Consume ammo (if available) and return the amount of ammo that was consumed.

Parameters
qtymaximum amount of ammo that should be consumed
poscurrent location of item, used for ejecting magazines and similar effects
Returns
amount of ammo consumed which will be between 0 and qty

Definition at line 7493 of file item.cpp.

7494{
7495 if( qty < 0 ) {
7496 debugmsg( "Cannot consume negative quantity of ammo for %s", tname() );
7497 return 0;
7498 }
7499
7500 item *mag = magazine_current();
7501 if( mag ) {
7502 const int res = mag->ammo_consume( qty, pos );
7503 if( res && ammo_remaining() == 0 ) {
7504 if( mag->has_flag( flag_MAG_DESTROY ) ) {
7505 remove_item( *mag );
7506 } else if( mag->has_flag( flag_MAG_EJECT ) ) {
7507 get_map().add_item( pos, *mag );
7508 remove_item( *mag );
7509 }
7510 }
7511 return res;
7512 }
7513
7514 if( is_magazine() ) {
7515 int need = qty;
7516 while( !contents.empty() ) {
7517 item &e = contents.front();
7518 if( need >= e.charges ) {
7519 need -= e.charges;
7521 } else {
7522 e.charges -= need;
7523 need = 0;
7524 break;
7525 }
7526 }
7527 return qty - need;
7528
7529 } else if( is_tool() || is_gun() ) {
7530 qty = std::min( qty, charges );
7532 avatar &you = get_avatar();
7535 }
7536 charges -= qty;
7537 if( charges == 0 ) {
7538 curammo = nullptr;
7539 }
7540 return qty;
7541 }
7542
7543 return 0;
7544}
avatar & get_avatar()
Definition: avatar.cpp:104
void mod_power_level(const units::energy &npower)
Definition: character.cpp:1922
units::energy get_power_level() const
Definition: character.cpp:1902
Definition: avatar.h:55
item & front()
this is an artifact of the previous code using front() everywhere for contents.
std::string tname(unsigned int quantity=1, bool with_prefix=true, unsigned int truncate=0) const
Return the (translated) item name.
Definition: item.cpp:4557
int ammo_consume(int qty, const tripoint &pos)
Consume ammo (if available) and return the amount of ammo that was consumed.
Definition: item.cpp:7493
const itype * curammo
Definition: item.h:2174
item & add_item(const tripoint &p, item new_item)
Place an item on the map, despite the parameter name, this is not necessarily a new item.
Definition: map.cpp:4433
#define debugmsg(...)
Debug message of level DL::Error and class DC::DebugMsg, also includes the source file name and line,...
Definition: debug.h:74
static const std::string flag_USES_BIONIC_POWER("USES_BIONIC_POWER")
static const std::string flag_MAG_DESTROY("MAG_DESTROY")
static const std::string flag_MAG_EJECT("MAG_EJECT")
map & get_map()
Definition: map.cpp:147
constexpr value_type to_kilojoule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:46
constexpr quantity< value_type, energy_in_joule_tag > from_kilojoule(const value_type v)
Definition: units_energy.h:32

References map::add_item(), ammo_consume(), ammo_remaining(), charges, contents, curammo, debugmsg, item_contents::empty(), flag_MAG_DESTROY(), flag_MAG_EJECT(), flag_USES_BIONIC_POWER(), units::from_kilojoule(), item_contents::front(), get_avatar(), get_map(), Character::get_power_level(), has_flag(), is_gun(), is_magazine(), is_tool(), magazine_current(), Character::mod_power_level(), visitable< item >::remove_item(), tname(), and units::to_kilojoule().

Referenced by ammo_consume(), vehicle_part::ammo_consume(), Character::consume_charges(), iuse::einktabletpc(), ranged::fire_gun(), activity_handlers::game_do_turn(), iuse::gasmask(), iuse::multicooker(), iuse::note_bionics(), activity_handlers::oxytorch_do_turn(), npc::pretend_fire(), process_tool(), reload(), activity_handlers::repair_item_finish(), toolweapon_on(), and activity_handlers::vibe_do_turn().

◆ ammo_current()

itype_id item::ammo_current ( ) const

Specific ammo type, returns "null" if item is neither ammo nor loaded with any.

Definition at line 7572 of file item.cpp.

7573{
7574 const itype *ammo = ammo_data();
7575 return ammo ? ammo->get_id() : itype_id::NULL_ID();
7576}
const itype * ammo_data() const
Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.
Definition: item.cpp:7546
const itype_id & get_id() const
Definition: itype.cpp:88

References ammo_data(), itype::get_id(), and string_id< itype >::NULL_ID().

Referenced by vehicle_part::ammo_current(), turret_data::ammo_options(), npc::confident_gun_mode_range(), display_name(), aim_activity_actor::do_turn(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), get_remaining_capacity_for_liquid(), gun_noise(), npc_ai::gun_value(), ideal_ranged_dps(), is_reloadable_helper(), make_gun_projectile(), parse_tags(), remove_ammo(), activity_handlers::repair_item_finish(), stacks_with(), avatar_funcs::unload_item(), iuse_transform::use(), and weight().

◆ ammo_data()

const itype * item::ammo_data ( ) const

Specific ammo data, returns nullptr if item is neither ammo nor loaded with any.

Definition at line 7546 of file item.cpp.

7547{
7548 const item *mag = magazine_current();
7549 if( mag ) {
7550 return mag->ammo_data();
7551 }
7552
7553 if( is_ammo() ) {
7554 return type;
7555 }
7556
7557 if( is_magazine() ) {
7558 return !contents.empty() ? contents.front().ammo_data() : nullptr;
7559 }
7560
7561 auto mods = is_gun() ? gunmods() : toolmods();
7562 for( const item *e : mods ) {
7563 if( !e->type->mod->ammo_modifier.empty() && e->ammo_current() &&
7564 e->ammo_current().is_valid() ) {
7565 return &*e->ammo_current();
7566 }
7567 }
7568
7569 return curammo;
7570}
bool is_ammo() const
Definition: item.cpp:6590

References ammo_data(), contents, curammo, item_contents::empty(), item_contents::front(), gunmods(), is_ammo(), is_gun(), is_magazine(), magazine_current(), toolmods(), and type.

Referenced by ammo_current(), ammo_data(), turret_data::ammo_data(), ammo_effects(), ammo_info(), cycle_action(), Character::deactivate_bionic(), avatar_action::fire_wielded_weapon(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), ranged::handle_gun_damage(), is_reloadable_helper(), make_gun_projectile(), Item_modifier::modify(), price(), character_funcs::select_ammo(), target_ui::update_ammo_range_from_gun_mode(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_default()

itype_id item::ammo_default ( bool  conversion = true) const

Get default ammo used by item or a null id if item does not have a default ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id::NULL_ID() if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7609 of file item.cpp.

7610{
7611 if( is_magazine() ) {
7612 return type->magazine->default_ammo;
7613 }
7614
7615 const std::set<ammotype> &atypes = ammo_types( conversion );
7616 if( !atypes.empty() ) {
7617 itype_id res = ammotype( *atypes.begin() )->default_ammotype();
7618 if( !res.is_empty() ) {
7619 return res;
7620 }
7621 }
7622 return itype_id::NULL_ID();
7623}
const itype_id & default_ammotype() const
Definition: ammo.h:21
bool is_empty() const
Returns whether this id is empty.
Definition: string_id.h:298
string_id< ammunition_type > ammotype
Definition: type_id.h:12

References ammo_types(), ammunition_type::default_ammotype(), string_id< T >::is_empty(), is_magazine(), itype::magazine, string_id< itype >::NULL_ID(), and type.

Referenced by basecamp::add_resource(), turret_data::ammo_current(), crafting::complete_disassemble(), game::dump_stats(), npc::enough_time_to_reload(), inventory::form_from_map(), gun_info(), npc_ai::gun_value(), ideal_ranged_dps(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), starting_inv(), iexamine::use_furn_fake_item(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_effects()

std::set< ammo_effect_str_id > item::ammo_effects ( bool  with_ammo = true) const

Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.

Definition at line 7641 of file item.cpp.

7642{
7643 if( !is_gun() ) {
7644 return std::set<ammo_effect_str_id>();
7645 }
7646
7647 std::set<ammo_effect_str_id> res = type->gun->ammo_effects;
7648 if( with_ammo && ammo_data() ) {
7649 res.insert( ammo_data()->ammo->ammo_effects.begin(), ammo_data()->ammo->ammo_effects.end() );
7650 }
7651
7652 for( const item *mod : gunmods() ) {
7653 res.insert( mod->type->gunmod->ammo_effects.begin(), mod->type->gunmod->ammo_effects.end() );
7654 }
7655
7656 return res;
7657}

References ammo_data(), itype::gun, gunmods(), is_gun(), and type.

Referenced by turret_data::ammo_effects(), gun_noise(), ranged::handle_gun_damage(), and make_gun_projectile().

◆ ammo_info()

void item::ammo_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1907 of file item.cpp.

1909{
1910 if( is_gun() || !ammo_data() || !parts->test( iteminfo_parts::AMMO_REMAINING_OR_TYPES ) ) {
1911 return;
1912 }
1913
1914 const std::string space = " ";
1915 if( ammo_remaining() > 0 ) {
1916 info.emplace_back( "AMMO", _( "<bold>Ammunition</bold>: " ),
1917 ammo_data()->nname( ammo_remaining() ) );
1918 } else if( is_ammo() ) {
1919 info.emplace_back( "AMMO", _( "<bold>Ammunition type</bold>: " ), ammo_type()->name() );
1920 }
1921
1922 const islot_ammo &ammo = *ammo_data()->ammo;
1923 if( !ammo.damage.empty() || ammo.force_stat_display ) {
1924 bool has_flat_dmg = !ammo.damage.empty() && ammo.damage.damage_units.front().amount > 0;
1925 bool display_flat_dmg = parts->test( iteminfo_parts::AMMO_DAMAGE_VALUE );
1926 // TODO: Multiple units
1927 bool has_dmg_multiplier = ammo.damage.damage_units.front().damage_multiplier != 1.0;
1928 bool display_dmg_multiplier = parts->test( iteminfo_parts::AMMO_DAMAGE_PROPORTIONAL );
1929 bool didnt_print_dmg = false;
1930 if( has_flat_dmg && has_dmg_multiplier
1931 && has_dmg_multiplier && display_dmg_multiplier ) {
1932 info.emplace_back( "AMMO", _( "Damage: " ), "",
1934 info.emplace_back( "AMMO", "/", "",
1936 ammo.damage.damage_units.front().damage_multiplier );
1937 // Messy ifs...
1938 } else if( display_dmg_multiplier && ( has_dmg_multiplier || !has_flat_dmg ) ) {
1939 info.emplace_back( "AMMO", _( "Damage multiplier: " ), "",
1941 ammo.damage.damage_units.front().damage_multiplier );
1942 } else if( display_flat_dmg ) {
1943 info.emplace_back( "AMMO", _( "Damage: " ), "",
1945 } else {
1946 didnt_print_dmg = true;
1947 }
1948
1949 // Ugly, but handles edge cases better than mandatory space
1950 static const std::string no_space;
1951 const std::string &maybe_space = didnt_print_dmg ? no_space : space;
1952
1953 // TODO: Deduplicate with damage display
1954 bool has_flat_arpen = get_ranged_pierce( ammo ) != 0;
1955 bool display_flat_arpen = parts->test( iteminfo_parts::AMMO_DAMAGE_AP );
1956 bool has_armor_mult = get_ranged_armor_mult( ammo ) != 1.0;
1957 bool display_armor_mult = parts->test( iteminfo_parts::AMMO_DAMAGE_AP_PROPORTIONAL );
1958 if( has_flat_arpen && display_flat_arpen
1959 && has_armor_mult && display_armor_mult ) {
1960 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), "",
1962 info.emplace_back( "AMMO", "/", "",
1964 get_ranged_armor_mult( ammo ) );
1965 } else if( has_armor_mult && display_armor_mult ) {
1966 info.emplace_back( "AMMO", maybe_space + _( "Armor multiplier: " ), "",
1968 } else if( display_flat_arpen ) {
1969 info.emplace_back( "AMMO", maybe_space + _( "Armor-pierce: " ), get_ranged_pierce( ammo ) );
1970 }
1971 if( parts->test( iteminfo_parts::AMMO_DAMAGE_RANGE ) ) {
1972 info.emplace_back( "AMMO", _( "Range: " ), "", iteminfo::no_newline, ammo.shape
1973 ? static_cast<int>( ammo.shape->get_range() )
1974 : ammo.range );
1975 }
1977 info.emplace_back( "AMMO", space + _( "Dispersion: " ), "",
1979 }
1981 info.emplace_back( "AMMO", _( "Recoil: " ), "",
1983 }
1984 }
1985
1986 // TODO: De-hardcode. Have it imply a flag? Just include description_on_item in ammo_effect struct?
1987 std::vector<std::string> fx;
1988 if( ammo.shape &&
1989 parts->test( iteminfo_parts::AMMO_SHAPE ) ) {
1990 fx.emplace_back( string_format(
1991 _( "This ammo will produce effects with the following shape:\n<bold>%s</bold>" ),
1992 ammo.shape->get_description() ) );
1993 }
1994 if( ammo.ammo_effects.count( ammo_effect_RECYCLED ) &&
1996 fx.emplace_back( _( "This ammo has been <bad>hand-loaded</bad>." ) );
1997 }
1998 if( ammo.ammo_effects.count( ammo_effect_BLACKPOWDER ) &&
2000 fx.emplace_back(
2001 _( "This ammo has been loaded with <bad>blackpowder</bad>, and will quickly "
2002 "clog up most guns, and cause rust if the gun is not cleaned." ) );
2003 }
2004 if( ammo.ammo_effects.count( ammo_effect_NEVER_MISFIRES ) &&
2006 fx.emplace_back( _( "This ammo <good>never misfires</good>." ) );
2007 }
2008 if( ammo.ammo_effects.count( ammo_effect_INCENDIARY ) &&
2010 fx.emplace_back( _( "This ammo <neutral>starts fires</neutral>." ) );
2011 }
2012 if( !fx.empty() ) {
2014 for( const std::string &e : fx ) {
2015 info.emplace_back( "AMMO", e );
2016 }
2017 }
2018}
static std::string nname(const itype_id &id, unsigned int quantity=1)
Returns the translated item name for the item with given id.
Definition: item.cpp:9943
std::vector< iteminfo > info() const
Return all the information about the item and its type as a vector.
Definition: item.cpp:3974
ammotype ammo_type() const
Ammo type of an ammo item.
Definition: item.cpp:7601
bool test(const iteminfo_parts &value) const
static const ammo_effect_str_id ammo_effect_NEVER_MISFIRES("NEVER_MISFIRES")
static float get_ranged_armor_mult(const common_ranged_data &ranged)
Definition: item.cpp:1103
static const ammo_effect_str_id ammo_effect_INCENDIARY("INCENDIARY")
static const ammo_effect_str_id ammo_effect_BLACKPOWDER("BLACKPOWDER")
static void insert_separation_line(std::vector< iteminfo > &info)
Definition: item.cpp:1304
static int get_ranged_pierce(const common_ranged_data &ranged)
Definition: item.cpp:1094
static const ammo_effect_str_id ammo_effect_RECYCLED("RECYCLED")
@ AMMO_DAMAGE_AP_PROPORTIONAL
std::string name(type dir)
Get Human readable name of a direction.
Definition: overmap.cpp:4129
int dispersion
Dispersion "bonus" from gun.
Definition: itype.h:420
damage_instance damage
Damage, armor piercing and multipliers for each.
Definition: itype.h:412
int range
Range bonus from gun.
Definition: itype.h:416
std::vector< damage_unit > damage_units
Definition: damage.h:52
float total_damage() const
Definition: damage.cpp:75
bool empty() const
Definition: damage.cpp:88
std::optional< bool > force_stat_display
Some combat ammo might not have a damage value Set this to make it show as combat ammo anyway.
Definition: itype.h:733
std::optional< shape_factory > shape
AoE shape or null if it's a projectile.
Definition: itype.h:738
int recoil
Recoil (per shot), roughly equivalent to kinetic energy (in Joules)
Definition: itype.h:713
std::set< ammo_effect_str_id > ammo_effects
See ammo_effect struct.
Definition: itype.h:705
@ no_newline
Do not follow with a newline.
Definition: item.h:147
@ is_decimal
Print as decimal rather than integer.
Definition: item.h:145
@ lower_is_better
Lower values are better for this stat.
Definition: item.h:148
cata::value_ptr< islot_ammo > ammo
Definition: itype.h:864
#define _(msg)
Definition: translations.h:116

References _, itype::ammo, AMMO_DAMAGE_AP, AMMO_DAMAGE_AP_PROPORTIONAL, AMMO_DAMAGE_DISPERSION, AMMO_DAMAGE_PROPORTIONAL, AMMO_DAMAGE_RANGE, AMMO_DAMAGE_RECOIL, AMMO_DAMAGE_VALUE, ammo_data(), ammo_effect_BLACKPOWDER, ammo_effect_INCENDIARY, ammo_effect_NEVER_MISFIRES, ammo_effect_RECYCLED, islot_ammo::ammo_effects, AMMO_FX_BLACKPOWDER, AMMO_FX_CANTMISSFIRE, AMMO_FX_INCENDIARY, AMMO_FX_RECYCLED, ammo_remaining(), AMMO_REMAINING_OR_TYPES, AMMO_SHAPE, ammo_type(), common_ranged_data::damage, damage_instance::damage_units, common_ranged_data::dispersion, damage_instance::empty(), islot_ammo::force_stat_display, get_ranged_armor_mult(), get_ranged_pierce(), info(), insert_separation_line(), is_ammo(), iteminfo::is_decimal, is_gun(), iteminfo::lower_is_better, om_direction::name(), nname(), iteminfo::no_newline, common_ranged_data::range, islot_ammo::recoil, islot_ammo::shape, sign::space, string_format(), iteminfo_query::test(), and damage_instance::total_damage().

Referenced by info().

◆ ammo_remaining()

int item::ammo_remaining ( ) const

Quantity of ammunition currently loaded in tool, gun or auxiliary gunmod.

Definition at line 7395 of file item.cpp.

7396{
7397 const item *mag = magazine_current();
7398 if( mag ) {
7399 return mag->ammo_remaining();
7400 }
7401
7402 if( is_tool() || is_gun() ) {
7403 // includes auxiliary gunmods
7405 int power = units::to_kilojoule( get_avatar().get_power_level() );
7406 return power;
7407 }
7408 return charges;
7409 }
7410
7411 if( is_magazine() || is_bandolier() ) {
7412 int res = 0;
7413 for( const item *e : contents.all_items_top() ) {
7414 res += e->charges;
7415 }
7416 return res;
7417 }
7418
7419 return 0;
7420}

References item_contents::all_items_top(), ammo_remaining(), charges, contents, flag_USES_BIONIC_POWER(), get_avatar(), has_flag(), is_bandolier(), is_gun(), is_magazine(), is_tool(), magazine_current(), and units::to_kilojoule().

Referenced by game::add_artifact_dreams(), ammo_consume(), character_funcs::ammo_count_for(), ammo_info(), ammo_remaining(), vehicle_part::ammo_remaining(), turret_data::ammo_remaining(), vehicle_part::ammo_set(), ammo_sufficient(), item_funcs::can_be_unloaded(), turret_data::can_reload(), turret_data::can_unload(), firestarter_actor::can_use(), Character::consume_charges(), iuse::cs_lajatang_off(), Character::deactivate_bionic(), display_name(), npc::do_reload(), aim_activity_actor::do_turn(), iuse::ehandcuffs(), iuse::einktabletpc(), fill_with(), ranged::fire_gun(), character_funcs::fmt_wielded_weapon(), iuse::foodperson(), get_remaining_capacity_for_liquid(), getlight_emit(), gun_recoil(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), activity_handlers::hand_crank_do_turn(), Character::has_enough_charges(), ideal_ranged_dps(), vehicle::interact_with(), is_gunmod_compatible(), is_reloadable_helper(), item(), item_action_generator::map_actions_to_items(), Item_modifier::modify(), iuse::multicooker(), iuse::oxytorch(), target_ui::panel_gun_info(), price(), game::process_artifact(), Character::process_items(), relic_funcs::process_recharge(), process_vehicle_items(), item_reload_option::qty(), iuse::radio_on(), avatar_action::reload(), reload(), activity_handlers::repair_item_finish(), item_funcs::shots_remaining(), iuse::tazer2(), tool_info(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse::vibe(), activity_handlers::vibe_do_turn(), wants_to_reload(), wants_to_reload_with(), weapon_inventory_preset::weapon_inventory_preset(), and weight().

◆ ammo_required()

int item::ammo_required ( ) const

Quantity of ammunition consumed per usage of tool or with each shot of gun.

Definition at line 7465 of file item.cpp.

7466{
7467 if( is_tool() ) {
7468 return std::max( type->charges_to_use(), 0 );
7469 }
7470
7471 if( is_gun() ) {
7472 if( ammo_types().empty() ) {
7473 return 0;
7474 } else if( has_flag( flag_FIRE_100 ) ) {
7475 return 100;
7476 } else if( has_flag( flag_FIRE_50 ) ) {
7477 return 50;
7478 } else if( has_flag( flag_FIRE_20 ) ) {
7479 return 20;
7480 } else {
7481 return 1;
7482 }
7483 }
7484
7485 return 0;
7486}
static const std::string flag_FIRE_100("FIRE_100")
static const std::string flag_FIRE_50("FIRE_50")
static const std::string flag_FIRE_20("FIRE_20")
int charges_to_use() const
Definition: itype.cpp:110

References ammo_types(), itype::charges_to_use(), flag_FIRE_100(), flag_FIRE_20(), flag_FIRE_50(), has_flag(), is_gun(), is_tool(), and type.

Referenced by character_funcs::ammo_count_for(), turret_data::ammo_options(), ammo_sufficient(), firestarter_actor::can_use(), cauterize_actor::can_use(), Character::consume_charges(), salvage_actor::cut_up(), display_name(), npc::do_reload(), ranged::fire_gun(), mattack::frag(), activity_handlers::game_do_turn(), activatable_inventory_preset::get_denial(), gun_recoil(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), vehicle::interact_with(), activity_handlers::jackhammer_finish(), item_action_generator::map_actions_to_items(), iuse::oxytorch(), activity_handlers::oxytorch_do_turn(), activity_handlers::pickaxe_finish(), iuse::portable_game(), turret_data::prepare_fire(), npc::pretend_fire(), process_tool(), turret_data::query(), activity_handlers::repair_item_finish(), mattack::rifle(), item_funcs::shots_remaining(), mattack::tankgun(), units_sufficient(), inscribe_actor::use(), cauterize_actor::use(), enzlave_actor::use(), wants_to_reload(), and wants_to_reload_with().

◆ ammo_set()

item & item::ammo_set ( const itype_id ammo,
int  qty = -1 
)

Filter setting the ammo for this instance Any existing ammo is removed.

If necessary a magazine is also added.

Parameters
ammospecific type of ammo (must be compatible with item ammo type)
qtymaximum ammo (capped by item capacity) or negative to fill to capacity
Returns
same instance to allow method chaining

Definition at line 593 of file item.cpp.

594{
595 if( qty < 0 ) {
596 // completely fill an integral or existing magazine
598 qty = ammo_capacity();
599
600 // else try to add a magazine using default ammo count property if set
601 } else if( !magazine_default().is_null() ) {
602 item mag( magazine_default() );
603 if( mag.type->magazine->count > 0 ) {
604 qty = mag.type->magazine->count;
605 } else {
606 qty = item( magazine_default() ).ammo_capacity();
607 }
608 }
609 }
610
611 if( qty <= 0 ) {
612 ammo_unset();
613 return *this;
614 }
615
616 // handle reloadable tools and guns with no specific ammo type as special case
617 if( ( ammo.is_null() && ammo_types().empty() ) || is_money() ) {
618 if( ( is_tool() || is_gun() ) && magazine_integral() ) {
619 curammo = nullptr;
620 charges = std::min( qty, ammo_capacity() );
621 }
622 return *this;
623 }
624
625 // check ammo is valid for the item
626 const itype *atype = &*ammo;
627 if( !atype->ammo || !ammo_types().count( atype->ammo->type ) ) {
628 debugmsg( "Tried to set invalid ammo %s[%d] for %s", atype->get_id(), qty, typeId() );
629 return *this;
630 }
631
632 if( is_magazine() ) {
633 ammo_unset();
634 item set_ammo( ammo, calendar::turn, std::min( qty, ammo_capacity() ) );
635 if( has_flag( flag_NO_UNLOAD ) ) {
636 set_ammo.set_flag( "NO_DROP" );
637 set_ammo.set_flag( "IRREMOVABLE" );
638 }
639 put_in( set_ammo );
640
641 } else if( magazine_integral() ) {
642 curammo = atype;
643 charges = std::min( qty, ammo_capacity() );
644
645 } else {
646 if( !magazine_current() ) {
648 if( !mag->magazine ) {
649 debugmsg( "Tried to set ammo %s[%d] without suitable magazine for %s",
650 atype->get_id(), qty, typeId() );
651 return *this;
652 }
653
654 // if default magazine too small fetch instead closest available match
655 if( mag->magazine->capacity < qty ) {
656 // as above call to magazine_default successful can infer minimum one option exists
657 auto iter = type->magazines.find( atype->ammo->type );
658 if( iter == type->magazines.end() ) {
659 debugmsg( "%s doesn't have a magazine for %s",
660 typeId(), ammo );
661 return *this;
662 }
663 std::vector<itype_id> opts( iter->second.begin(), iter->second.end() );
664 std::sort( opts.begin(), opts.end(), []( const itype_id & lhs, const itype_id & rhs ) {
665 return lhs->magazine->capacity < rhs->magazine->capacity;
666 } );
667 mag = opts.back();
668 for( const itype_id &e : opts ) {
669 if( e->magazine->capacity >= qty ) {
670 mag = e;
671 break;
672 }
673 }
674 }
675 put_in( item( mag ) );
676 }
677 magazine_current()->ammo_set( ammo, qty );
678 }
679
680 return *this;
681}
bool is_money() const
Definition: item.cpp:6008
item & ammo_unset()
Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-o...
Definition: item.cpp:683
bool is_null() const
Returns whether this represents the id of the null-object (in which case it's the null-id).
Definition: string_id.h:317
static const std::string flag_NO_UNLOAD("NO_UNLOAD")
std::map< ammotype, std::set< itype_id > > magazines
Magazine types (if any) for each ammo type that can be used to reload this item.
Definition: itype.h:1020

References itype::ammo, ammo_capacity(), ammo_set(), ammo_types(), ammo_unset(), charges, count(), curammo, debugmsg, flag_NO_UNLOAD(), itype::get_id(), has_flag(), is_gun(), is_magazine(), is_money(), is_null(), string_id< T >::is_null(), is_tool(), item(), itype::magazine, magazine_current(), magazine_default(), magazine_integral(), itype::magazines, put_in(), set_flag(), calendar::turn, type, and typeId().

Referenced by Character::activate_bionic(), ammo_set(), vehicle_part::ammo_set(), mdeath::broken(), npc::check_toggle_cbm(), crafting::complete_disassemble(), vehicle_part::deserialize(), game::dump_stats(), fill_with(), find_reloadable_cbms(), basecamp::form_crafting_inventory(), gun_info(), npc_ai::gun_value(), activity_handlers::hand_crank_do_turn(), vehicle::interact_with(), item(), Item_modifier::modify(), relic_funcs::process_recharge_entry(), gun_actor::shoot(), npc::starting_weapon(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), iuse_transform::use(), npc_ai::wielded_value(), and debug_menu::wishitem().

◆ ammo_sort_name()

std::string item::ammo_sort_name ( ) const

Definition at line 7659 of file item.cpp.

7660{
7661 if( is_magazine() || is_gun() || is_tool() ) {
7662 const std::set<ammotype> &types = ammo_types();
7663 if( !types.empty() ) {
7664 return ammotype( *types.begin() )->name();
7665 }
7666 }
7667 if( is_ammo() ) {
7668 return ammo_type()->name();
7669 }
7670 return "";
7671}
std::string name() const
Definition: ammo.cpp:79

References ammo_type(), ammo_types(), is_ammo(), is_gun(), is_magazine(), is_tool(), and ammunition_type::name().

◆ ammo_sufficient()

bool item::ammo_sufficient ( int  qty = 1) const

Check if sufficient ammo is loaded for given number of uses.

Check if there is enough ammo loaded in a tool for the given number of uses or given number of gun shots. Using this function for this check is preferred because we expect to add support for items consuming multiple ammo types in the future. Users of this function will not need to be refactored when this happens.

Parameters
[in]qtyNumber of uses
Returns
true if ammo sufficient for number of uses is loaded, false otherwise

Definition at line 7488 of file item.cpp.

7489{
7490 return ammo_remaining() >= ammo_required() * qty;
7491}
int ammo_required() const
Quantity of ammunition consumed per usage of tool or with each shot of gun.
Definition: item.cpp:7465

References ammo_remaining(), and ammo_required().

Referenced by can_do_activity_there(), iuse::extinguisher(), ranged::gunmode_checks_weapon(), Character::has_enough_charges(), iuse::jet_injector(), item_action_generator::map_actions_to_items(), mine_activity(), avatar_action::move(), iuse::pheromone(), iuse::portal(), turret_data::query(), iuse::radiocar(), iuse::radiocaron(), examine_item_menu::rate_action_use(), iuse::rm13armor_off(), iuse::shavekit(), gun_actor::shoot(), iuse::stimpack(), and iuse::teleport().

◆ ammo_type()

ammotype item::ammo_type ( ) const

Ammo type of an ammo item.

Returns
ammotype of ammo item or a null id if the item is not ammo

Definition at line 7601 of file item.cpp.

7602{
7603 if( is_ammo() ) {
7604 return type->ammo->type;
7605 }
7606 return ammotype::NULL_ID();
7607}

References itype::ammo, is_ammo(), string_id< ammunition_type >::NULL_ID(), and type.

Referenced by vehicle::add_item(), ammo_info(), ammo_sort_name(), mdeath::broken(), color_in_inventory(), detonate(), character_funcs::find_ammo_helper(), character_funcs::get_ammo_items(), item_reload_option::qty(), reload(), and npc::value().

◆ ammo_types()

const std::set< ammotype > & item::ammo_types ( bool  conversion = true) const

Set of ammo types (ammunition_type) used by item.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
empty set if item does not use a specific ammo type (and is consequently not reloadable)

Definition at line 7578 of file item.cpp.

7579{
7580 if( conversion ) {
7581 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7582 for( const item *e : mods ) {
7583 if( !e->type->mod->ammo_modifier.empty() ) {
7584 return e->type->mod->ammo_modifier;
7585 }
7586 }
7587 }
7588
7589 if( is_gun() ) {
7590 return type->gun->ammo;
7591 } else if( is_tool() ) {
7592 return type->tool->ammo_id;
7593 } else if( is_magazine() ) {
7594 return type->magazine->type;
7595 }
7596
7597 static std::set<ammotype> atypes = {};
7598 return atypes;
7599}

References itype::gun, gunmods(), is_gun(), is_magazine(), is_tool(), itype::magazine, itype::tool, toolmods(), and type.

Referenced by vehicle::add_item(), allow_crafting_component(), ammo_default(), turret_data::ammo_options(), ammo_required(), ammo_set(), ammo_sort_name(), mdeath::broken(), item_funcs::can_be_unloaded(), color_in_inventory(), common_ammo_default(), craft_has_charges(), display_name(), avatar_action::fire_wielded_weapon(), get_quality(), avatar_funcs::gunmod_add(), vehicle_part::is_battery(), is_gunmod_compatible(), is_money(), is_reloadable(), is_reloadable_helper(), item(), magazine_compatible(), magazine_default(), magazine_info(), Item_modifier::modify(), price(), relic_funcs::process_recharge_entry(), character_funcs::select_ammo(), set_countdown(), tool_info(), avatar_funcs::unload_item(), npc::value(), and weight().

◆ ammo_unset()

item & item::ammo_unset ( )

Filter removing all ammo from this instance If the item is neither a tool, gun nor magazine is a no-op For items reloading using magazines any empty magazine remains present.

Definition at line 683 of file item.cpp.

684{
685 if( !is_tool() && !is_gun() && !is_magazine() ) {
686 // do nothing
687 } else if( is_magazine() ) {
689 } else if( magazine_integral() ) {
690 curammo = nullptr;
691 charges = 0;
692 } else if( magazine_current() ) {
694 }
695
696 return *this;
697}

References ammo_unset(), charges, item_contents::clear_items(), contents, curammo, is_gun(), is_magazine(), is_tool(), magazine_current(), and magazine_integral().

Referenced by ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), iuse::ehandcuffs(), emit_radio_signal(), npc_ai::gun_value(), and ammobelt_actor::use().

◆ animal_armor_info()

void item::animal_armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2718 of file item.cpp.

2720{
2721 if( !is_pet_armor() ) {
2722 return;
2723 }
2724
2725 const std::string space = " ";
2726
2727 int converted_storage_scale = 0;
2728 const double converted_storage = round_up( convert_volume( get_storage().value(),
2729 &converted_storage_scale ), 2 );
2730 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2731 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2732 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2733 string_format( "<num> %s", volume_units_abbr() ),
2734 f, converted_storage ) );
2735 }
2736
2737 // Whatever the last entry was, we want a newline at this point
2738 info.back().bNewLine = true;
2739
2740 armor_protection_info( info, parts, batch, debug );
2741}
double round_up(double val, unsigned int dp)
Round a value up at a given decimal place.
units::volume get_storage() const
Returns the storage amount (islot_armor::storage) that this item provides when worn.
Definition: item.cpp:5740
void armor_protection_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2492
bool is_pet_armor(bool on_pet=false) const
Definition: item.cpp:6706
constexpr auto debug
Definition: options.cpp:151
Value and metadata for one property of an item.
Definition: item.h:108
flags
Definition: item.h:143
@ no_flags
Definition: item.h:144
const char * volume_units_abbr()
Create an abbreviated units label for a volume value.
double convert_volume(int volume)
Convert volume from ml to units defined by user.

References _, armor_protection_info(), ARMOR_STORAGE, convert_volume(), debug, get_storage(), info(), iteminfo::is_decimal, is_pet_armor(), iteminfo::no_flags, round_up(), sign::space, string_format(), iteminfo_query::test(), and volume_units_abbr().

Referenced by info().

◆ armor_fit_info()

void item::armor_fit_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2743 of file item.cpp.

2745{
2746 if( !is_armor() ) {
2747 return;
2748 }
2749
2750 avatar &you = get_avatar();
2751 int encumbrance = get_encumber( you );
2752 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2753
2756 info.push_back( iteminfo( "DESCRIPTION",
2757 _( "* This item can be <info>worn with a "
2758 "helmet</info>." ) ) );
2759 }
2760
2762 switch( sizing_level ) {
2764 if( has_flag( flag_FIT ) ) {
2765 info.emplace_back( "DESCRIPTION",
2766 _( "* This clothing <info>fits</info> you perfectly." ) );
2767 }
2768 break;
2770 if( has_flag( flag_FIT ) ) {
2771 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2772 "your large frame perfectly." ) );
2773 }
2774 break;
2776 if( has_flag( flag_FIT ) ) {
2777 info.emplace_back( "DESCRIPTION", _( "* This clothing <info>fits</info> "
2778 "your small frame perfectly." ) );
2779 }
2780 break;
2782 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>oversized</bad> "
2783 "and does <bad>not fit</bad> you." ) );
2784 break;
2786 info.emplace_back( "DESCRIPTION",
2787 _( "* This clothing is hilariously <bad>oversized</bad> "
2788 "and does <bad>not fit</bad> your <info>abnormally "
2789 "small mutated anatomy</info>." ) );
2790 break;
2792 info.emplace_back( "DESCRIPTION",
2793 _( "* This clothing is <bad>normal sized</bad> and does "
2794 "<bad>not fit</info> your <info>abnormally large "
2795 "mutated anatomy</info>." ) );
2796 break;
2798 info.emplace_back( "DESCRIPTION",
2799 _( "* This clothing is <bad>normal sized</bad> and does "
2800 "<bad>not fit</bad> your <info>abnormally small "
2801 "mutated anatomy</info>." ) );
2802 break;
2804 info.emplace_back( "DESCRIPTION",
2805 _( "* This clothing is hilariously <bad>undersized</bad> "
2806 "and does <bad>not fit</bad> your <info>abnormally "
2807 "large mutated anatomy</info>." ) );
2808 break;
2810 info.emplace_back( "DESCRIPTION", _( "* This clothing is <bad>undersized</bad> "
2811 "and does <bad>not fit</bad> you." ) );
2812 break;
2813 default:
2814 break;
2815 }
2816 }
2817
2819 if( has_flag( flag_VARSIZE ) ) {
2820 std::string resize_str;
2821 if( has_flag( flag_FIT ) ) {
2822 switch( sizing_level ) {
2824 resize_str = _( "<info>can be upsized</info>" );
2825 break;
2827 resize_str = _( "<info>can be downsized</info>" );
2828 break;
2831 resize_str = _( "<bad>can not be downsized</bad>" );
2832 break;
2835 resize_str = _( "<bad>can not be upsized</bad>" );
2836 break;
2837 default:
2838 break;
2839 }
2840 if( !resize_str.empty() ) {
2841 std::string info_str = string_format( _( "* This clothing %s." ), resize_str );
2842 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2843 }
2844 } else {
2845 switch( sizing_level ) {
2847 resize_str = _( " and <info>upsized</info>" );
2848 break;
2850 resize_str = _( " and <info>downsized</info>" );
2851 break;
2854 resize_str = _( " but <bad>not downsized</bad>" );
2855 break;
2858 resize_str = _( " but <bad>not upsized</bad>" );
2859 break;
2860 default:
2861 break;
2862 }
2863 std::string info_str = string_format( _( "* This clothing <info>can be "
2864 "refitted</info>%s." ), resize_str );
2865 info.push_back( iteminfo( "DESCRIPTION", info_str ) );
2866 }
2867 } else {
2868 info.emplace_back( "DESCRIPTION", _( "* This clothing <bad>can not be refitted, "
2869 "upsized, or downsized</bad>." ) );
2870 }
2871 }
2872
2874 info.push_back( iteminfo( "DESCRIPTION",
2875 _( "* This item can be worn on <info>either side</info> of "
2876 "the body." ) ) );
2877 }
2878 if( ( is_power_armor() ) &&
2882 info.push_back( iteminfo( "DESCRIPTION",
2883 _( "* When worn with a power armor suit, it will "
2884 "<good>fully protect</good> you from "
2885 "<info>radiation</info>." ) ) );
2886 } else if( has_flag( flag_POWERARMOR_EXO ) ) {
2887 info.push_back( iteminfo( "DESCRIPTION",
2888 _( "* When worn with a power armor helmet, it will "
2889 "<good>fully protect</good> you from " "<info>radiation</info>." ) ) );
2890 }
2891 }
2892 }
2894 info.push_back( iteminfo( "DESCRIPTION",
2895 string_format( _( "* The film strip on the badge is %s." ),
2897 }
2898}
@ bp_head
Definition: bodypart.h:42
bool is_sided() const
Returns true if item is armor and can be worn on different sides of the body.
Definition: item.cpp:805
int irradiation
Definition: item.h:2211
bool is_power_armor() const
Whether this is a power armor item.
Definition: item.cpp:5794
sizing
Definition: item.h:2130
@ small_sized_small_char
@ human_sized_human_char
@ small_sized_human_char
@ human_sized_small_char
bool is_armor() const
Definition: item.cpp:6712
sizing get_sizing(const Character &, bool) const
Definition: item.cpp:1180
int get_encumber(const Character &) const
Returns the encumbrance value that this item has when worn by given player.
Definition: item.cpp:5800
bool covers(body_part bp) const
Whether this item (when worn) covers the given body part.
Definition: item.cpp:746
static const std::string flag_FIT("FIT")
static const std::string flag_HELMET_COMPAT("HELMET_COMPAT")
static const std::string flag_POWERARMOR_EXO("POWERARMOR_EXO")
static const itype_id itype_rad_badge("rad_badge")
static const std::string flag_VARSIZE("VARSIZE")
static const std::string flag_POWERARMOR_EXTERNAL("POWERARMOR_EXTERNAL")
std::string rad_badge_color(const int rad)
Definition: item.cpp:292
@ DESCRIPTION_FLAGS_POWERARMOR
@ DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT
@ DESCRIPTION_FLAGS_HELMETCOMPAT

References _, big_sized_big_char, big_sized_human_char, big_sized_small_char, bp_head, covers(), DESCRIPTION_FLAGS_FITS, DESCRIPTION_FLAGS_HELMETCOMPAT, DESCRIPTION_FLAGS_POWERARMOR, DESCRIPTION_FLAGS_POWERARMOR_RADIATIONHINT, DESCRIPTION_FLAGS_SIDED, DESCRIPTION_FLAGS_VARSIZE, DESCRIPTION_IRRADIATION, flag_FIT(), flag_HELMET_COMPAT(), flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_VARSIZE(), get_avatar(), get_encumber(), get_sizing(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, info(), irradiation, is_armor(), is_power_armor(), is_sided(), itype_rad_badge, rad_badge_color(), small_sized_big_char, small_sized_human_char, small_sized_small_char, string_format(), iteminfo_query::test(), and typeId().

Referenced by final_info().

◆ armor_info()

void item::armor_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2535 of file item.cpp.

2537{
2538 if( !is_armor() ) {
2539 return;
2540 }
2541
2542 avatar &you = get_avatar();
2543 int encumbrance = get_encumber( you );
2544 const sizing sizing_level = get_sizing( you, encumbrance != 0 );
2545 const std::string space = " ";
2546 body_part_set covered_parts = get_covered_body_parts();
2547 bool covers_anything = covered_parts.any();
2548
2549 if( parts->test( iteminfo_parts::ARMOR_BODYPARTS ) ) {
2551 std::string coverage = _( "<bold>Covers</bold>: " );
2552 if( covers( bp_head ) ) {
2553 coverage += _( "The <info>head</info>. " );
2554 }
2555 if( covers( bp_eyes ) ) {
2556 coverage += _( "The <info>eyes</info>. " );
2557 }
2558 if( covers( bp_mouth ) ) {
2559 coverage += _( "The <info>mouth</info>. " );
2560 }
2561 if( covers( bp_torso ) ) {
2562 coverage += _( "The <info>torso</info>. " );
2563 }
2564
2565 if( is_sided() && ( covers( bp_arm_l ) || covers( bp_arm_r ) ) ) {
2566 coverage += _( "Either <info>arm</info>. " );
2567 } else if( covers( bp_arm_l ) && covers( bp_arm_r ) ) {
2568 coverage += _( "The <info>arms</info>. " );
2569 } else if( covers( bp_arm_l ) ) {
2570 coverage += _( "The <info>left arm</info>. " );
2571 } else if( covers( bp_arm_r ) ) {
2572 coverage += _( "The <info>right arm</info>. " );
2573 }
2574
2575 if( is_sided() && ( covers( bp_hand_l ) || covers( bp_hand_r ) ) ) {
2576 coverage += _( "Either <info>hand</info>. " );
2577 } else if( covers( bp_hand_l ) && covers( bp_hand_r ) ) {
2578 coverage += _( "The <info>hands</info>. " );
2579 } else if( covers( bp_hand_l ) ) {
2580 coverage += _( "The <info>left hand</info>. " );
2581 } else if( covers( bp_hand_r ) ) {
2582 coverage += _( "The <info>right hand</info>. " );
2583 }
2584
2585 if( is_sided() && ( covers( bp_leg_l ) || covers( bp_leg_r ) ) ) {
2586 coverage += _( "Either <info>leg</info>. " );
2587 } else if( covers( bp_leg_l ) && covers( bp_leg_r ) ) {
2588 coverage += _( "The <info>legs</info>. " );
2589 } else if( covers( bp_leg_l ) ) {
2590 coverage += _( "The <info>left leg</info>. " );
2591 } else if( covers( bp_leg_r ) ) {
2592 coverage += _( "The <info>right leg</info>. " );
2593 }
2594
2595 if( is_sided() && ( covers( bp_foot_l ) || covers( bp_foot_r ) ) ) {
2596 coverage += _( "Either <info>foot</info>. " );
2597 } else if( covers( bp_foot_l ) && covers( bp_foot_r ) ) {
2598 coverage += _( "The <info>feet</info>. " );
2599 } else if( covers( bp_foot_l ) ) {
2600 coverage += _( "The <info>left foot</info>. " );
2601 } else if( covers( bp_foot_r ) ) {
2602 coverage += _( "The <info>right foot</info>. " );
2603 }
2604
2605 if( !covers_anything ) {
2606 coverage += _( "<info>Nothing</info>." );
2607 }
2608
2609 info.push_back( iteminfo( "ARMOR", coverage ) );
2610 }
2611
2612 if( parts->test( iteminfo_parts::ARMOR_LAYER ) && covers_anything ) {
2613 std::string layering = _( "Layer: " );
2614 if( has_flag( flag_PERSONAL ) ) {
2615 layering += _( "<stat>Personal aura</stat>. " );
2616 } else if( has_flag( flag_SKINTIGHT ) ) {
2617 layering += _( "<stat>Close to skin</stat>. " );
2618 } else if( has_flag( flag_BELTED ) ) {
2619 layering += _( "<stat>Strapped</stat>. " );
2620 } else if( has_flag( flag_OUTER ) ) {
2621 layering += _( "<stat>Outer</stat>. " );
2622 } else if( has_flag( flag_WAIST ) ) {
2623 layering += _( "<stat>Waist</stat>. " );
2624 } else if( has_flag( flag_AURA ) ) {
2625 layering += _( "<stat>Outer aura</stat>. " );
2626 } else {
2627 layering += _( "<stat>Normal</stat>. " );
2628 }
2629
2630 info.push_back( iteminfo( "ARMOR", layering ) );
2631 }
2632
2633 if( parts->test( iteminfo_parts::ARMOR_COVERAGE ) && covers_anything ) {
2634 info.push_back( iteminfo( "ARMOR", _( "Coverage: " ), "<num>%",
2636 }
2637 if( parts->test( iteminfo_parts::ARMOR_WARMTH ) && covers_anything ) {
2638 info.push_back( iteminfo( "ARMOR", space + _( "Warmth: " ), get_warmth() ) );
2639 }
2640
2642
2643 if( parts->test( iteminfo_parts::ARMOR_ENCUMBRANCE ) && covers_anything ) {
2644 std::string format;
2645 if( has_flag( flag_FIT ) ) {
2646 format = _( "<num> <info>(fits)</info>" );
2647 } else if( has_flag( flag_VARSIZE ) && encumbrance ) {
2648 format = _( "<num> <bad>(poor fit)</bad>" );
2649 }
2650
2651 //If we have the wrong size, we do not fit so alert the player
2652 if( sizing_level == sizing::human_sized_small_char ) {
2653 format = _( "<num> <bad>(too big)</bad>" );
2654 } else if( sizing_level == sizing::big_sized_small_char ) {
2655 format = _( "<num> <bad>(huge!)</bad>" );
2656 } else if( sizing_level == sizing::small_sized_human_char ||
2657 sizing_level == sizing::human_sized_big_char ) {
2658 format = _( "<num> <bad>(too small)</bad>" );
2659 } else if( sizing_level == sizing::small_sized_big_char ) {
2660 format = _( "<num> <bad>(tiny!)</bad>" );
2661 }
2662
2663 info.push_back( iteminfo( "ARMOR", _( "<bold>Encumbrance</bold>: " ), format,
2665 encumbrance ) );
2666 if( !type->rigid ) {
2667 const int encumbrance_when_full =
2669 info.push_back( iteminfo( "ARMOR", space + _( "Encumbrance when full: " ), "",
2671 encumbrance_when_full ) );
2672 }
2673 }
2674
2675 int converted_storage_scale = 0;
2676 const double converted_storage = round_up( convert_volume( get_storage().value(),
2677 &converted_storage_scale ), 2 );
2678 if( parts->test( iteminfo_parts::ARMOR_STORAGE ) && converted_storage > 0 ) {
2679 const iteminfo::flags f = converted_storage_scale == 0 ? iteminfo::no_flags : iteminfo::is_decimal;
2680 info.push_back( iteminfo( "ARMOR", space + _( "Storage: " ),
2681 string_format( "<num> %s", volume_units_abbr() ),
2682 f, converted_storage ) );
2683 }
2684
2685 // Whatever the last entry was, we want a newline at this point
2686 info.back().bNewLine = true;
2687
2688 if( covers_anything ) {
2689 armor_protection_info( info, parts, batch, debug );
2690 }
2691
2692 const units::mass weight_bonus = get_weight_capacity_bonus();
2693 const float weight_modif = get_weight_capacity_modifier();
2694 if( weight_modif != 1 ) {
2695 std::string modifier;
2696 if( weight_modif < 1 ) {
2697 modifier = "<num><bad>x</bad>";
2698 } else {
2699 modifier = "<num><color_light_green>x</color>";
2700 }
2701 info.push_back( iteminfo( "ARMOR",
2702 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
2703 iteminfo::no_newline | iteminfo::is_decimal, weight_modif ) );
2704 }
2705 if( weight_bonus != 0_gram ) {
2706 std::string bonus;
2707 if( weight_bonus < 0_gram ) {
2708 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
2709 } else {
2710 bonus = string_format( "<num> <color_light_green> %s</color>", weight_units() );
2711 }
2712 info.push_back( iteminfo( "ARMOR", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
2714 convert_weight( weight_bonus ) ) );
2715 }
2716}
@ bp_foot_l
Definition: bodypart.h:51
@ bp_leg_r
Definition: bodypart.h:50
@ bp_eyes
Definition: bodypart.h:43
@ bp_hand_l
Definition: bodypart.h:47
@ bp_arm_l
Definition: bodypart.h:45
@ bp_leg_l
Definition: bodypart.h:49
@ bp_hand_r
Definition: bodypart.h:48
@ bp_torso
Definition: bodypart.h:41
@ bp_mouth
Definition: bodypart.h:44
@ bp_foot_r
Definition: bodypart.h:52
@ bp_arm_r
Definition: bodypart.h:46
bool any() const
Definition: bodypart.h:262
units::volume get_total_capacity() const
It returns the maximum volume of any contents, including liquids, ammo, magazines,...
Definition: item.cpp:8417
int get_encumber_when_containing(const Character &, const units::volume &contents_volume) const
Returns the encumbrance value that this item has when worn by given player, when containing a particu...
Definition: item.cpp:5828
units::mass get_weight_capacity_bonus() const
Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides whe...
Definition: item.cpp:5762
body_part_set get_covered_body_parts() const
Bitset of all covered body parts.
Definition: item.cpp:756
int get_warmth() const
Returns the warmth value that this item has when worn.
Definition: item.cpp:5926
int get_coverage() const
Returns the relative coverage that this item has when worn.
Definition: item.cpp:5908
float get_weight_capacity_modifier() const
Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides ...
Definition: item.cpp:5753
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&... args)
\rst Formats arguments and returns the result as a string.
Definition: fmtlib_core.h:2316
static const std::string flag_WAIST("WAIST")
static const std::string flag_BELTED("BELTED")
static const std::string flag_SKINTIGHT("SKINTIGHT")
static const std::string flag_OUTER("OUTER")
static const std::string flag_AURA("AURA")
static const std::string flag_PERSONAL("PERSONAL")
bool rigid
Definition: itype.h:991
const char * weight_units()
Create a units label for a weight value.
double convert_weight(const units::mass &weight)
Convert weight in grams to units defined by user (kg or lbs)

References _, body_part_set::any(), ARMOR_BODYPARTS, ARMOR_COVERAGE, ARMOR_ENCUMBRANCE, ARMOR_LAYER, armor_protection_info(), ARMOR_STORAGE, ARMOR_WARMTH, big_sized_small_char, bp_arm_l, bp_arm_r, bp_eyes, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_head, bp_leg_l, bp_leg_r, bp_mouth, bp_torso, convert_volume(), convert_weight(), covers(), debug, flag_AURA(), flag_BELTED(), flag_FIT(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_VARSIZE(), flag_WAIST(), format(), get_avatar(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_sizing(), get_storage(), get_total_capacity(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), has_flag(), human_sized_big_char, human_sized_small_char, info(), insert_separation_line(), is_armor(), iteminfo::is_decimal, is_sided(), iteminfo::lower_is_better, iteminfo::no_flags, iteminfo::no_newline, itype::rigid, round_up(), small_sized_big_char, small_sized_human_char, sign::space, string_format(), iteminfo_query::test(), type, volume_units_abbr(), and weight_units().

Referenced by info().

◆ armor_protection_info()

void item::armor_protection_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2492 of file item.cpp.

2495{
2496 if( !is_armor() && !is_pet_armor() ) {
2497 return;
2498 }
2499
2500 const std::string space = " ";
2501
2502 if( parts->test( iteminfo_parts::ARMOR_PROTECTION ) ) {
2503 info.push_back( iteminfo( "ARMOR", _( "<bold>Protection</bold>: Bash: " ), "",
2505 info.push_back( iteminfo( "ARMOR", space + _( "Cut: " ), "", iteminfo::no_newline, cut_resist() ) );
2506 info.push_back( iteminfo( "ARMOR", space + _( "Ballistic: " ), bullet_resist() ) );
2507 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2509 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2511 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2512 get_base_env_resist( *this ) ) );
2513 if( type->can_use( "GASMASK" ) || type->can_use( "DIVE_TANK" ) ) {
2514 info.push_back( iteminfo( "ARMOR",
2515 _( "<bold>Protection when active</bold>: " ) ) );
2516 info.push_back( iteminfo( "ARMOR", space + _( "Acid: " ), "",
2519 info.push_back( iteminfo( "ARMOR", space + _( "Fire: " ), "",
2522 info.push_back( iteminfo( "ARMOR", space + _( "Environmental: " ),
2524 }
2525
2526 if( damage() > 0 ) {
2527 info.push_back( iteminfo( "ARMOR",
2528 _( "Protection values are <bad>reduced by damage</bad> and "
2529 "you may be able to <info>improve them by repairing this "
2530 "item</info>." ) ) );
2531 }
2532 }
2533}
int bash_resist(bool to_self=false) const
Definition: item.cpp:6039
int fire_resist(bool to_self=false, int base_env_resist=0) const
Definition: item.cpp:6169
int acid_resist(bool to_self=false, int base_env_resist=0) const
Resistance against different damage types (damage_type).
Definition: item.cpp:6135
int bullet_resist(bool to_self=false) const
Definition: item.cpp:6106
int get_base_env_resist_w_filter() const
Returns the base resistance to environmental effects if an item (for example a gas mask) requires a g...
Definition: item.cpp:5785
int cut_resist(bool to_self=false) const
Definition: item.cpp:6067
int damage() const
How much damage has the item sustained?
Definition: item.cpp:699
static int get_base_env_resist(const item &it)
Definition: item.cpp:1223
bool can_use(const std::string &iuse_name) const
Definition: itype.cpp:161

References _, acid_resist(), ARMOR_PROTECTION, bash_resist(), bullet_resist(), itype::can_use(), cut_resist(), damage(), fire_resist(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), info(), is_armor(), is_pet_armor(), iteminfo::no_newline, sign::space, iteminfo_query::test(), and type.

Referenced by animal_armor_info(), and armor_info().

◆ attack_cost()

int item::attack_cost ( ) const

Base number of moves (Creature::moves) that a single melee attack with this items takes.

The actual time depends heavily on the attacker, see melee.cpp.

Definition at line 5189 of file item.cpp.

5190{
5191 int base = 65 + ( volume() / 62.5_ml + weight() / 60_gram ) / count();
5193 return std::max( 0, base + bonus );
5194}
double bonus_from_enchantments_wielded(double base, enchant_vals::mod value, bool round=false) const
Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantment...
Definition: item.cpp:7014
units::mass weight(bool include_contents=true, bool integral=false) const
Definition: item.cpp:4966
units::volume volume(bool integral=false) const
Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to n...
Definition: item.cpp:5112

References bonus_from_enchantments_wielded(), count(), enchant_vals::ITEM_ATTACK_COST, volume(), and weight().

Referenced by Character::attack_cost(), combat_info(), Character::melee_attack(), npc::move_to(), smash(), and ranged::throw_cost().

◆ average_dps()

double item::average_dps ( const player guy) const

return the average dps of the weapon against evaluation monsters

Definition at line 1451 of file item.cpp.

1452{
1453 double dmg_count = 0.0;
1454 const std::map<std::string, double> &dps_data = dps( false, true, guy );
1455 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
1456 dmg_count += dps_entry.second;
1457 }
1458 return dmg_count / dps_data.size();
1459}
std::map< std::string, double > dps(bool for_display, bool for_calc, const player &guy) const
calculate effective dps against a stock set of monsters.
Definition: item.cpp:1431

References dps().

Referenced by npc_ai::melee_value().

◆ base_damage_melee()

damage_instance item::base_damage_melee ( ) const

All damage types this item deals when used in melee (no skill modifiers etc.

applied).

Definition at line 5252 of file item.cpp.

5253{
5254 // TODO: Caching
5256 for( size_t i = DT_NULL + 1; i < NUM_DT; i++ ) {
5257 damage_type dt = static_cast<damage_type>( i );
5258 int dam = damage_melee( dt );
5259 if( dam > 0 ) {
5260 ret.add_damage( dt, dam );
5261 }
5262 }
5263
5264 return ret;
5265}
int damage_melee(damage_type dt) const
Damage of given type caused when this item is used as melee weapon.
Definition: item.cpp:5196
damage_type
Definition: damage.h:20
@ DT_NULL
Definition: damage.h:21
@ NUM_DT
Definition: damage.h:32

References damage_melee(), DT_NULL, NUM_DT, and cata::hash64_detail::ret.

◆ base_damage_thrown()

damage_instance item::base_damage_thrown ( ) const

All damage types this item deals when thrown (no skill modifiers etc.

applied).

Definition at line 5267 of file item.cpp.

5268{
5269 // TODO: Create a separate cache for individual items (for modifiers like diamond etc.)
5270 return type->thrown_damage;
5271}
damage_instance thrown_damage
Base damage output when thrown.
Definition: itype.h:996

References itype::thrown_damage, and type.

Referenced by ranged::throw_item().

◆ base_volume()

units::volume item::base_volume ( ) const

Simplified, faster volume check for when processing time is important and exact volume is not.

NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge. If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Definition at line 5084 of file item.cpp.

5085{
5086 if( is_null() ) {
5087 return 0_ml;
5088 }
5089 if( is_corpse() ) {
5090 return corpse_volume( corpse );
5091 }
5092
5093 if( is_craft() ) {
5094 units::volume ret = 0_ml;
5095 for( const item &it : components ) {
5096 ret += it.base_volume();
5097 }
5098 return ret;
5099 }
5100
5101 if( count_by_charges() ) {
5102 if( type->volume % type->stack_size == 0_ml ) {
5103 return type->volume / type->stack_size;
5104 } else {
5105 return type->volume / type->stack_size + 1_ml;
5106 }
5107 }
5108
5109 return type->volume;
5110}
bool count_by_charges() const
Definition: item.cpp:6013
units::volume corpse_volume(const mtype *corpse) const
Volume check for corpses, helper for base_volume().
Definition: item.cpp:5062
bool is_craft() const
Definition: item.cpp:6931
bool is_corpse() const
Whether this is a corpse item.
Definition: item.cpp:6628
int stack_size
Number of items per above volume for count_by_charges items.
Definition: itype.h:982
units::volume volume
Space occupied by items of this type CAUTION: value given is for a default-sized stack.
Definition: itype.h:974

References components, corpse, corpse_volume(), count_by_charges(), is_corpse(), is_craft(), is_null(), cata::hash64_detail::ret, itype::stack_size, type, and itype::volume.

Referenced by burn(), flammable(), and simulate_burn().

◆ bash_resist()

int item::bash_resist ( bool  to_self = false) const

Definition at line 6039 of file item.cpp.

6040{
6041 if( is_null() ) {
6042 return 0;
6043 }
6044
6045 float resist = 0;
6047 int eff_thickness = 1;
6048
6049 // base resistance
6050 // Don't give reinforced items +armor, just more resistance to ripping
6051 const int dmg = damage_level( 4 );
6052 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6053 eff_thickness = std::max( 1, get_thickness() - eff_damage );
6054
6055 const std::vector<const material_type *> mat_types = made_of_types();
6056 if( !mat_types.empty() ) {
6057 for( const material_type *mat : mat_types ) {
6058 resist += mat->bash_resist();
6059 }
6060 // Average based on number of materials.
6061 resist /= mat_types.size();
6062 }
6063
6064 return std::lround( ( resist * eff_thickness ) + mod );
6065}
int get_thickness() const
Returns the islot_armor::thickness value, or 0 for non-armor.
Definition: item.cpp:5917
int damage_level(int max) const
Scale item damage to the given number of levels.
Definition: item.cpp:704
@ clothing_mod_type_bash
Definition: clothing_mod.h:19
STL namespace.

References clothing_mod_type_bash, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ basic_info()

void item::basic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1461 of file item.cpp.

1463{
1465 info.emplace_back( "BASE", string_format( _( "<stat>Origin: %s</stat>" ),
1466 enumerate_as_string( type->src.begin(),
1467 type->src.end(), []( const std::pair<itype_id, mod_id> &source ) {
1468 return string_format( "'%s'", source.second->name() );
1471 }
1473 info.emplace_back( "BASE", colorize( string_format( "[%s]", type->get_id() ), c_light_blue ) );
1475 }
1476
1477 const std::string space = " ";
1478 if( parts->test( iteminfo_parts::BASE_MATERIAL ) ) {
1479 const std::vector<const material_type *> mat_types = made_of_types();
1480 if( !mat_types.empty() ) {
1481 const std::string material_list = enumerate_as_string( mat_types.begin(), mat_types.end(),
1482 []( const material_type * material ) {
1483 return string_format( "<stat>%s</stat>", material->name() );
1485 info.push_back( iteminfo( "BASE", string_format( _( "Material: %s" ), material_list ) ) );
1486 }
1487 }
1488 if( parts->test( iteminfo_parts::BASE_VOLUME ) ) {
1489 int converted_volume_scale = 0;
1490 const double converted_volume = round_up( convert_volume( volume().value(),
1491 &converted_volume_scale ) * batch, 3 );
1493 if( converted_volume_scale != 0 ) {
1495 }
1496 info.push_back( iteminfo( "BASE", _( "Volume: " ),
1497 string_format( "<num> %s", volume_units_abbr() ),
1498 f, converted_volume ) );
1499 }
1500 if( parts->test( iteminfo_parts::BASE_WEIGHT ) ) {
1501 info.push_back( iteminfo( "BASE", space + _( "Weight: " ),
1502 string_format( "<num> %s", weight_units() ),
1504 convert_weight( weight() ) * batch ) );
1505 }
1506 if( !owner.is_null() ) {
1507 info.push_back( iteminfo( "BASE", string_format( _( "Owner: %s" ),
1508 _( get_owner_name() ) ) ) );
1509 }
1510 if( parts->test( iteminfo_parts::BASE_CATEGORY ) ) {
1511 info.push_back( iteminfo( "BASE", _( "Category: " ),
1512 "<header>" + get_category().name() + "</header>" ) );
1513 }
1514 if( !type->weapon_category.empty() && parts->test( iteminfo_parts::WEAPON_CATEGORY ) ) {
1515 const std::string weapon_categories = enumerate_as_string( type->weapon_category.begin(),
1516 type->weapon_category.end(), [&]( const weapon_category_id & elem ) {
1517 return elem->name().translated();
1519 info.push_back( iteminfo( "BASE", _( "Weapon Category: " ),
1520 "<header>" + weapon_categories + "</header>" ) );
1521 }
1522
1523 if( parts->test( iteminfo_parts::DESCRIPTION ) ) {
1525 const std::map<std::string, std::string>::const_iterator idescription =
1526 item_vars.find( "description" );
1527 const std::optional<translation> snippet = SNIPPET.get_snippet_by_id( snip_id );
1528 if( snippet.has_value() ) {
1529 // Just use the dynamic description
1530 info.push_back( iteminfo( "DESCRIPTION", snippet.value().translated() ) );
1531 } else if( idescription != item_vars.end() ) {
1532 info.push_back( iteminfo( "DESCRIPTION", idescription->second ) );
1533 } else {
1534 if( has_flag( "MAGIC_FOCUS" ) ) {
1535 info.push_back( iteminfo( "DESCRIPTION",
1536 _( "This item is a <info>magical focus</info>. "
1537 "You can cast spells with it in your hand." ) ) );
1538 }
1539 if( is_craft() ) {
1540 const std::string desc = _( "This is an in progress %s. "
1541 "It is %d percent complete." );
1542 const int percent_progress = item_counter / 100000;
1543 info.push_back( iteminfo( "DESCRIPTION", string_format( desc,
1544 craft_data_->making->result_name(),
1545 percent_progress ) ) );
1546 } else {
1547 info.push_back( iteminfo( "DESCRIPTION", type->description.translated() ) );
1548 }
1549 }
1551 }
1552
1554
1555 if( parts->test( iteminfo_parts::BASE_REQUIREMENTS ) ) {
1556 // Display any minimal stat or skill requirements for the item
1557 std::vector<std::string> req;
1558 if( get_min_str() > 0 ) {
1559 avatar &viewer = get_avatar();
1560 if( has_flag( flag_STR_DRAW ) && ranged::get_str_draw_penalty( *this, viewer ) < 1.0f ) {
1561 if( ranged::get_str_draw_penalty( *this, viewer ) < 0.5f ) {
1562 req.push_back( string_format( _( "%s %d <color_magenta>(Can't use!)</color>" ), _( "strength" ),
1563 get_min_str() ) );
1564 } else if( ranged::get_str_draw_penalty( *this, viewer ) < 0.75f ) {
1565 req.push_back( string_format( "%s %d <color_red>(Damage/Range 0.5x, Dispersion 2.0x)</color>",
1566 _( "strength" ), get_min_str() ) );
1567 } else {
1568 req.push_back( string_format( "%s %d <color_yellow>(Damage/Range 0.75x)</color>", _( "strength" ),
1569 get_min_str() ) );
1570 }
1571 } else {
1572 req.push_back( string_format( "%s %d", _( "strength" ), get_min_str() ) );
1573 }
1574 }
1575 if( type->min_dex > 0 ) {
1576 req.push_back( string_format( "%s %d", _( "dexterity" ), type->min_dex ) );
1577 }
1578 if( type->min_int > 0 ) {
1579 req.push_back( string_format( "%s %d", _( "intelligence" ), type->min_int ) );
1580 }
1581 if( type->min_per > 0 ) {
1582 req.push_back( string_format( "%s %d", _( "perception" ), type->min_per ) );
1583 }
1584 for( const std::pair<const skill_id, int> sk : sorted_lex( type->min_skills ) ) {
1585 req.push_back( string_format( "%s %d", skill_id( sk.first )->name(), sk.second ) );
1586 }
1587 if( !req.empty() ) {
1588 info.emplace_back( "BASE", _( "<bold>Minimum requirements</bold>:" ) );
1589 info.emplace_back( "BASE", enumerate_as_string( req ) );
1591 }
1592 }
1593
1594 if( has_var( "contained_name" ) && parts->test( iteminfo_parts::BASE_CONTENTS ) ) {
1595 info.push_back( iteminfo( "BASE", string_format( _( "Contains: %s" ),
1596 get_var( "contained_name" ) ) ) );
1597 }
1598 if( count_by_charges() && !is_food() && !is_medication() &&
1599 parts->test( iteminfo_parts::BASE_AMOUNT ) ) {
1600 info.push_back( iteminfo( "BASE", _( "Amount: " ), "<num>", iteminfo::no_flags,
1601 charges * batch ) );
1602 }
1603 if( debug && parts->test( iteminfo_parts::BASE_DEBUG ) ) {
1604 if( g != nullptr ) {
1605 info.push_back( iteminfo( "BASE", string_format( "itype_id: %s",
1606 typeId().c_str() ) ) );
1607 info.push_back( iteminfo( "BASE", _( "age (hours): " ), "", iteminfo::lower_is_better,
1608 to_hours<int>( age() ) ) );
1609 info.push_back( iteminfo( "BASE", _( "charges: " ), "", iteminfo::lower_is_better,
1610 charges ) );
1611 info.push_back( iteminfo( "BASE", _( "damage: " ), "", iteminfo::lower_is_better,
1612 damage_ ) );
1613 info.push_back( iteminfo( "BASE", _( "active: " ), "", iteminfo::lower_is_better,
1614 active ) );
1615 info.push_back( iteminfo( "BASE", _( "burn: " ), "", iteminfo::lower_is_better,
1616 burnt ) );
1617 const std::string tags_listed = enumerate_as_string( item_tags, enumeration_conjunction::none );
1618 info.push_back( iteminfo( "BASE", string_format( _( "tags: %s" ), tags_listed ) ) );
1619 for( auto const &imap : item_vars ) {
1620 info.push_back( iteminfo( "BASE",
1621 string_format( _( "item var: %s, %s" ), imap.first,
1622 imap.second ) ) );
1623 }
1624
1625 const item *food = get_food();
1626 if( food && food->goes_bad() ) {
1627 info.push_back( iteminfo( "BASE", _( "age (turns): " ),
1629 to_turns<int>( food->age() ) ) );
1630 info.push_back( iteminfo( "BASE", _( "rot (turns): " ),
1632 to_turns<int>( food->rot ) ) );
1633 info.push_back( iteminfo( "BASE", space + _( "max rot (turns): " ),
1635 to_turns<int>( food->get_shelf_life() ) ) );
1636 info.push_back( iteminfo( "BASE", _( "last rot: " ),
1638 to_turn<int>( food->last_rot_check ) ) );
1639 }
1640 }
1641 }
1642}
bool display_object_ids
Display internal IDs for items, furniture, terrain and monsters.
bool display_mod_source
Display mod source for items, furniture, terrain and monsters.
double get_var(const std::string &name, double default_value) const
Definition: item.cpp:1033
int burnt
Definition: item.h:2207
int get_min_str() const
Definition: item.cpp:10065
bool has_var(const std::string &name) const
Whether the variable is defined at all.
Definition: item.cpp:1078
time_duration age() const
Definition: item.cpp:10026
time_duration rot
Accumulated rot, expressed as time the item has been in standard temperature.
Definition: item.h:2227
faction_id owner
Definition: item.h:2233
bool is_medication() const
Definition: item.cpp:6606
time_duration get_shelf_life() const
Get the shelf life of the item.
Definition: item.cpp:5527
int damage_
Definition: item.h:2236
item * get_food()
Definition: item.cpp:6650
const item_category & get_category() const
Definition: item.cpp:8699
FlagsSetType item_tags
Definition: item.h:2171
std::string get_owner_name() const
Definition: item.cpp:1264
std::optional< translation > get_snippet_by_id(const snippet_id &id) const
Returns the snippet referenced by the id, or std::nullopt if there is no snippet with such id.
std::string translated(int num=1) const
Returns raw string if no translation is needed, otherwise returns the translated string.
std::string colorize(const std::string &text, const nc_color &color)
Definition: color.cpp:669
#define c_light_blue
Definition: color.h:29
std::unique_ptr< game > g
Definition: game.cpp:283
static const std::string flag_STR_DRAW("STR_DRAW")
std::vector< material_type > material_list
Definition: material.h:23
float get_str_draw_penalty(const item &it, const Character &p)
Penalties potentially incurred by STR_DRAW weapons.
Definition: ranged.cpp:1022
std::string enumerate_as_string(const _Container &values, enumeration_conjunction conj=enumeration_conjunction::and_)
Definition: output.h:637
std::vector< std::pair< K, V > > sorted_lex(Col col)
Returns vector sorted by lexicographic order of string_id.
@ is_three_decimal
Print as decimal with three points of precision.
Definition: item.h:146
int min_dex
Definition: itype.h:938
std::set< weapon_category_id > weapon_category
Definition: itype.h:905
int min_int
Definition: itype.h:939
int min_per
Definition: itype.h:940
translation description
Definition: itype.h:908
std::map< skill_id, int > min_skills
Definition: itype.h:936
std::vector< std::pair< itype_id, mod_id > > src
Definition: itype.h:841

References _, active, age(), arrow, BASE_AMOUNT, BASE_CATEGORY, BASE_CONTENTS, BASE_DEBUG, BASE_ID, BASE_MATERIAL, BASE_MOD_SRC, BASE_REQUIREMENTS, BASE_VOLUME, BASE_WEIGHT, burnt, c_light_blue, charges, colorize(), convert_volume(), convert_weight(), count_by_charges(), craft_data_, damage_, debug, DESCRIPTION, itype::description, display_mod_source, display_object_ids, enumerate_as_string(), flag_STR_DRAW(), g, get_avatar(), get_category(), get_food(), itype::get_id(), get_min_str(), get_owner_name(), get_shelf_life(), snippet_library::get_snippet_by_id(), ranged::get_str_draw_penalty(), get_var(), goes_bad(), has_flag(), has_var(), info(), insert_separation_line(), is_craft(), iteminfo::is_decimal, is_food(), is_medication(), string_id< T >::is_null(), iteminfo::is_three_decimal, item_counter, item_tags, item_vars, last_rot_check, iteminfo::lower_is_better, made_of_types(), itype::min_dex, itype::min_int, itype::min_per, itype::min_skills, om_direction::name(), iteminfo::no_flags, iteminfo::no_newline, none, owner, rot, round_up(), skill_id, snip_id, SNIPPET, sorted_lex(), sign::space, itype::src, string_format(), iteminfo_query::test(), translation::translated(), type, typeId(), volume(), volume_units_abbr(), WEAPON_CATEGORY, itype::weapon_category, weight(), and weight_units().

Referenced by info().

◆ battery_info()

void item::battery_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3065 of file item.cpp.

3067{
3068 if( !is_battery() ) {
3069 return;
3070 }
3071
3072 std::string info_string;
3073 if( type->battery->max_capacity < 1_kJ ) {
3074 info_string = string_format( _( "<bold>Capacity</bold>: %dJ" ),
3075 to_joule( type->battery->max_capacity ) );
3076 } else if( type->battery->max_capacity >= 1_kJ ) {
3077 info_string = string_format( _( "<bold>Capacity</bold>: %dkJ" ),
3078 to_kilojoule( type->battery->max_capacity ) );
3079 }
3081 info.emplace_back( "BATTERY", info_string );
3082}
bool is_battery() const
Definition: item.cpp:6570
std::string info_string() const
As info, but as a string rather than a vector of properties.
Definition: item.cpp:4069
constexpr value_type to_joule(const quantity< value_type, energy_in_joule_tag > &v)
Definition: units_energy.h:40
cata::value_ptr< islot_battery > battery
Definition: itype.h:862

References _, itype::battery, info(), info_string(), insert_separation_line(), is_battery(), string_format(), units::to_joule(), units::to_kilojoule(), and type.

Referenced by info().

◆ bionic_info()

void item::bionic_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3278 of file item.cpp.

3280{
3281 if( !is_bionic() ) {
3282 return;
3283 }
3284
3285 // TODO: Unhide when enforcing limits
3286 if( get_option < bool >( "CBM_SLOTS_ENABLED" )
3288 info.push_back( iteminfo( "DESCRIPTION", list_occupied_bps( type->bionic->id,
3289 _( "This bionic is installed in the following body "
3290 "part(s):" ) ) ) );
3291 }
3293
3294 const bionic_id bid = type->bionic->id;
3295 const std::vector<itype_id> &fuels = bid->fuel_opts;
3296 if( !fuels.empty() ) {
3297 const int &fuel_numb = fuels.size();
3298
3299 info.push_back( iteminfo( "DESCRIPTION",
3300 vgettext( "* This bionic can produce power from the following fuel: ",
3301 "* This bionic can produce power from the following fuels: ",
3302 fuel_numb ) + enumerate_as_string( fuels.begin(),
3303 fuels.end(), []( const itype_id & id ) -> std::string { return "<info>" + id->nname( 1 ) + "</info>"; } ) ) );
3304 }
3305
3307
3308 if( bid->capacity > 0_J ) {
3309 info.push_back( iteminfo( "CBM", _( "<bold>Power Capacity</bold>:" ), _( " <num> J" ),
3311 units::to_joule( bid->capacity ) ) );
3312 }
3313
3315
3316 if( !bid->encumbrance.empty() ) {
3317 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Encumbrance</bold>: " ),
3319 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->encumbrance ) ) {
3320 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3321 " <num> ", iteminfo::no_newline, element.second ) );
3322 }
3323 }
3324
3325 if( !bid->env_protec.empty() ) {
3326 info.push_back( iteminfo( "DESCRIPTION",
3327 bid->activated ? _( "<bold>Environmental Protection (activated)</bold>: " ) :
3328 _( "<bold>Environmental Protection</bold>: " ),
3330 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->env_protec ) ) {
3331 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3332 " <num> ", iteminfo::no_newline, element.second ) );
3333 }
3334 }
3335
3336 if( !bid->bash_protec.empty() ) {
3337 info.push_back( iteminfo( "DESCRIPTION",
3338 _( "<bold>Bash Protection</bold>: " ),
3340 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->bash_protec ) ) {
3341 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3342 " <num> ", iteminfo::no_newline, element.second ) );
3343 }
3344 }
3345
3346 if( !bid->cut_protec.empty() ) {
3347 info.push_back( iteminfo( "DESCRIPTION",
3348 _( "<bold>Cut Protection</bold>: " ),
3350 for( const std::pair< const bodypart_str_id, int > element : sorted_lex( bid->cut_protec ) ) {
3351 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3352 " <num> ", iteminfo::no_newline, element.second ) );
3353 }
3354 }
3355
3356 if( !bid->bullet_protec.empty() ) {
3357 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Ballistic Protection</bold>: " ),
3359 for( const auto &element : bid->bullet_protec ) {
3360 info.push_back( iteminfo( "CBM", body_part_name_as_heading( element.first->token, 1 ),
3361 " <num> ", iteminfo::no_newline, element.second ) );
3362 }
3363 }
3364
3365 if( !bid->stat_bonus.empty() ) {
3366 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Stat Bonus</bold>: " ),
3368 for( const auto &element : bid->stat_bonus ) {
3369 info.push_back( iteminfo( "CBM", get_stat_name( element.first ), " <num> ",
3370 iteminfo::no_newline, element.second ) );
3371 }
3372 }
3373
3374 const units::mass weight_bonus = bid->weight_capacity_bonus;
3375 const float weight_modif = bid->weight_capacity_modifier;
3376 if( weight_modif != 1 ) {
3377 std::string modifier;
3378 if( weight_modif < 1 ) {
3379 modifier = "<num><bad>x</bad>";
3380 } else {
3381 modifier = "<num><color_light_green>x</color>";
3382 }
3383 info.push_back( iteminfo( "CBM",
3384 _( "<bold>Weight capacity modifier</bold>: " ), modifier,
3386 weight_modif ) );
3387 }
3388 if( weight_bonus != 0_gram ) {
3389 std::string bonus;
3390 if( weight_bonus < 0_gram ) {
3391 bonus = string_format( "<num> <bad>%s</bad>", weight_units() );
3392 } else {
3393 bonus = string_format( "<num> <color_light_green>%s</color>", weight_units() );
3394 }
3395 info.push_back( iteminfo( "CBM", _( "<bold>Weight capacity bonus</bold>: " ), bonus,
3397 convert_weight( weight_bonus ) ) );
3398 }
3399}
std::string list_occupied_bps(const bionic_id &bio_id, const std::string &intro, const bool each_bp_on_new_line)
Definition: bionics.cpp:2544
std::string body_part_name_as_heading(body_part bp, int number)
Returns the name of the body parts in a context where the name is used as a heading or title e....
Definition: bodypart.cpp:343
std::string get_stat_name(character_stat Stat)
Get translated name of a stat.
Definition: character.cpp:7754
bool is_bionic() const
Definition: item.cpp:6560
std::map< bodypart_str_id, int > cut_protec
Amount of cut protection offered by this bionic.
Definition: bionics.h:88
units::energy capacity
Power bank size.
Definition: bionics.h:49
bool activated
Is true if a bionic is an active instead of a passive bionic.
Definition: bionics.h:53
std::map< character_stat, int > stat_bonus
Map of stats and their corresponding bonuses passively granted by a bionic.
Definition: bionics.h:63
std::vector< itype_id > fuel_opts
Fuel types that can be used by this bionic.
Definition: bionics.h:67
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: bionics.h:59
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: bionics.h:61
std::map< bodypart_str_id, int > encumbrance
Body part encumbered by this bionic, mapped to the amount of encumbrance caused.
Definition: bionics.h:99
std::map< bodypart_str_id, int > bullet_protec
Amount of bullet protection offered by this bionic.
Definition: bionics.h:90
std::map< bodypart_str_id, int > bash_protec
Amount of bash protection offered by this bionic.
Definition: bionics.h:86
std::map< bodypart_str_id, int > env_protec
Amount of environemental protection offered by this bionic.
Definition: bionics.h:84
cata::value_ptr< islot_bionic > bionic
Definition: itype.h:863
const char * vgettext(const char *msgid, const char *msgid_plural, size_t n)

References _, bionic_data::activated, bionic_data::bash_protec, itype::bionic, body_part_name_as_heading(), bionic_data::bullet_protec, bionic_data::capacity, convert_weight(), bionic_data::cut_protec, DESCRIPTION_CBM_SLOTS, bionic_data::encumbrance, enumerate_as_string(), bionic_data::env_protec, bionic_data::fuel_opts, get_stat_name(), info(), insert_separation_line(), is_bionic(), iteminfo::is_decimal, list_occupied_bps(), iteminfo::no_newline, sorted_lex(), bionic_data::stat_bonus, string_format(), iteminfo_query::test(), units::to_joule(), type, vgettext(), bionic_data::weight_capacity_bonus, bionic_data::weight_capacity_modifier, and weight_units().

Referenced by final_info().

◆ birthday()

◆ bonus_from_enchantments()

double item::bonus_from_enchantments ( const Character owner,
double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only.

Definition at line 6995 of file item.cpp.

6997{
6998 double add = 0.0;
6999 double mul = 0.0;
7000 for( const enchantment &ench : get_enchantments() ) {
7001 if( ench.is_active( owner, *this ) ) {
7002 add += ench.get_value_add( value );
7003 mul += ench.get_value_multiply( value );
7004 }
7005 }
7006 // TODO: this part duplicates enchantment::calc_bonus()
7007 double ret = add + base * mul;
7008 if( round ) {
7009 ret = trunc( ret );
7010 }
7011 return ret;
7012}
const std::vector< enchantment > & get_enchantments() const
Definition: item.cpp:6986
type add(type dir1, type dir2)
Returns a sum of two numbers.
Definition: overmap.cpp:4195

References om_direction::add(), get_enchantments(), owner, and cata::hash64_detail::ret.

Referenced by item_armor_enchantment_adjust().

◆ bonus_from_enchantments_wielded()

double item::bonus_from_enchantments_wielded ( double  base,
enchant_vals::mod  value,
bool  round = false 
) const

Calculate bonus from enchantments that affect this item only, assume it's wielded and all enchantments' conditions are satisfied.

Definition at line 7014 of file item.cpp.

7016{
7017 double add = 0.0;
7018 double mul = 0.0;
7019 for( const enchantment &ench : get_enchantments() ) {
7020 if( ench.is_active_when_wielded() ) {
7021 add += ench.get_value_add( value );
7022 mul += ench.get_value_multiply( value );
7023 }
7024 }
7025 // TODO: this part duplicates enchantment::calc_bonus()
7026 double ret = add + base * mul;
7027 if( round ) {
7028 ret = trunc( ret );
7029 }
7030 return ret;
7031}

References om_direction::add(), get_enchantments(), and cata::hash64_detail::ret.

Referenced by attack_cost(), and damage_melee().

◆ book_info()

void item::book_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2900 of file item.cpp.

2902{
2903 if( !is_book() ) {
2904 return;
2905 }
2906
2907 Character &character = get_player_character();
2908
2910 const islot_book &book = *type->book;
2911 // Some things about a book you CAN tell by it's cover.
2912 if( !book.skill && !type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2913 info.push_back( iteminfo( "BOOK", _( "Just for fun." ) ) );
2914 }
2915 if( type->can_use( "MA_MANUAL" ) && parts->test( iteminfo_parts::BOOK_SUMMARY ) ) {
2916 info.push_back( iteminfo( "BOOK",
2917 _( "Some sort of <info>martial arts training "
2918 "manual</info>." ) ) );
2919 const matype_id style_to_learn = martial_art_learned_from( *type );
2920 info.push_back( iteminfo( "BOOK",
2921 string_format( _( "You can learn <info>%s</info> style "
2922 "from it." ), style_to_learn->name ) ) );
2923 info.push_back( iteminfo( "BOOK",
2924 string_format( _( "This fighting style is <info>%s</info> "
2925 "to learn." ),
2926 martialart_difficulty( style_to_learn ) ) ) );
2927 info.push_back( iteminfo( "BOOK",
2928 string_format( _( "It'd be easier to master if you'd have "
2929 "skill expertise in <info>%s</info>." ),
2930 style_to_learn->primary_skill->name() ) ) );
2931 }
2932 if( book.req == 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_BEGINNER ) ) {
2933 info.push_back( iteminfo( "BOOK", _( "It can be <info>understood by "
2934 "beginners</info>." ) ) );
2935 }
2936 avatar &you = get_avatar();
2937 if( !you.has_identified( typeId() ) && parts->test( iteminfo_parts::BOOK_UNREAD ) ) {
2938 info.push_back( iteminfo( "BOOK",
2939 _( "You have <info>never read</info> this book." ) ) );
2940 }
2941 if( book.skill ) {
2942 const SkillLevel &skill = you.get_skill_level_object( book.skill );
2943 if( skill.can_train() && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MAX ) ) {
2944 const std::string skill_name = book.skill->name();
2945 std::string fmt = string_format( _( "Can bring your <info>%s skill to</info> "
2946 "<num>." ), skill_name );
2947 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, book.level ) );
2948 fmt = string_format( _( "Your current <stat>%s skill</stat> is <num>." ),
2949 skill_name );
2950 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, skill.level() ) );
2951 }
2952
2953 if( book.req != 0 && parts->test( iteminfo_parts::BOOK_SKILLRANGE_MIN ) ) {
2954 const std::string fmt = string_format(
2955 _( "<info>Requires %s level</info> <num> to "
2956 "understand." ), book.skill.obj().name() );
2957 info.push_back( iteminfo( "BOOK", "", fmt,
2959 }
2960 }
2961
2962 if( book.intel != 0 && parts->test( iteminfo_parts::BOOK_REQUIREMENTS_INT ) ) {
2963 info.push_back( iteminfo( "BOOK", "",
2964 _( "Requires <info>intelligence of</info> <num> to easily "
2965 "read." ), iteminfo::lower_is_better, book.intel ) );
2966 }
2967 if( character_funcs::get_book_fun_for( character, *this ) != 0 &&
2969 info.push_back( iteminfo( "BOOK", "",
2970 _( "Reading this book affects your morale by <num>" ),
2972 }
2974 std::string fmt = vgettext(
2975 "A chapter of this book takes <num> <info>minute to "
2976 "read</info>.",
2977 "A chapter of this book takes <num> <info>minutes to "
2978 "read</info>.", book.time );
2979 if( type->use_methods.count( "MA_MANUAL" ) ) {
2980 fmt = vgettext(
2981 "<info>A training session</info> with this book takes "
2982 "<num> <info>minute</info>.",
2983 "<info>A training session</info> with this book takes "
2984 "<num> <info>minutes</info>.", book.time );
2985 }
2986 info.push_back( iteminfo( "BOOK", "", fmt,
2988 }
2989
2990 if( book.chapters > 0 && parts->test( iteminfo_parts::BOOK_NUMUNREADCHAPTERS ) ) {
2991 const int unread = get_remaining_chapters( you );
2992 std::string fmt = vgettext( "This book has <num> <info>unread chapter</info>.",
2993 "This book has <num> <info>unread chapters</info>.",
2994 unread );
2995 info.push_back( iteminfo( "BOOK", "", fmt, iteminfo::no_flags, unread ) );
2996 }
2997
2998 std::vector<std::string> recipe_list;
2999 for( const islot_book::recipe_with_description_t &elem : book.recipes ) {
3000 const bool knows_it = you.knows_recipe( elem.recipe );
3001 const bool can_learn = you.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level;
3002 // If the player knows it, they recognize it even if it's not clearly stated.
3003 if( elem.is_hidden() && !knows_it ) {
3004 continue;
3005 }
3006 if( knows_it ) {
3007 // In case the recipe is known, but has a different name in the book, use the
3008 // real name to avoid confusing the player.
3009 const std::string name = elem.recipe->result_name();
3010 recipe_list.push_back( "<bold>" + name + "</bold>" );
3011 } else if( !can_learn ) {
3012 recipe_list.push_back( "<color_brown>" + elem.name + "</color>" );
3013 } else {
3014 recipe_list.push_back( "<dark>" + elem.name + "</dark>" );
3015 }
3016 }
3017
3018 if( !recipe_list.empty() && parts->test( iteminfo_parts::DESCRIPTION_BOOK_RECIPES ) ) {
3019 std::string recipe_line =
3020 string_format( vgettext( "This book contains %1$d crafting recipe: %2$s",
3021 "This book contains %1$d crafting recipes: %2$s",
3022 recipe_list.size() ),
3023 recipe_list.size(), enumerate_as_string( recipe_list ) );
3024
3026 info.push_back( iteminfo( "DESCRIPTION", recipe_line ) );
3027 }
3028
3029 if( recipe_list.size() != book.recipes.size() &&
3031 info.push_back( iteminfo( "DESCRIPTION",
3032 _( "It might help you figuring out some <good>more "
3033 "recipes</good>." ) ) );
3034 }
3035}
Character & get_player_character()
Definition: character.cpp:400
SkillLevel & get_skill_level_object(const skill_id &ident)
Definition: character.cpp:3348
bool knows_recipe(const recipe *rec) const
int get_skill_level(const skill_id &ident) const
Definition: character.cpp:3353
int level() const
Definition: skill.h:125
bool can_train() const
Definition: skill.cpp:311
std::string name() const
Definition: skill.h:68
bool has_identified(const itype_id &item_id) const
Note that we've read a book at least once.
Definition: avatar.cpp:953
bool is_book() const
Definition: item.cpp:6717
int get_remaining_chapters(const Character &ch) const
Get the number of unread chapters.
Definition: item.cpp:7105
translation name
Definition: martialarts.h:270
skill_id primary_skill
Definition: martialarts.h:274
std::string result_name() const
Definition: recipe.cpp:612
skill_id skill_used
Definition: recipe.h:109
@ BOOK_REQUIREMENTS_BEGINNER
@ DESCRIPTION_BOOK_ADDITIONAL_RECIPES
std::string martialart_difficulty(const matype_id &mstyle)
matype_id martial_art_learned_from(const itype &type)
Definition: martialarts.cpp:90
int get_book_fun_for(const Character &ch, const item &book)
Returns enjoyability value of a book for given character.
What recipes can be learned from this book.
Definition: itype.h:359
std::string name
The name for the recipe as it appears in the book.
Definition: itype.h:371
int skill_level
The skill level required to learn the recipe.
Definition: itype.h:367
const class recipe * recipe
The recipe that can be learned (never null).
Definition: itype.h:363
int level
The skill level the book provides.
Definition: itype.h:334
int intel
Intelligence required to read it.
Definition: itype.h:346
skill_id skill
Which skill it upgrades, if any.
Definition: itype.h:326
int req
The skill level required to understand it.
Definition: itype.h:338
recipe_list_t recipes
Definition: itype.h:384
int time
How long in minutes it takes to read.
Definition: itype.h:351
int chapters
Fun books have chapters; after all are read, the book is less fun.
Definition: itype.h:355
@ show_plus
Use a + sign for positive values.
Definition: item.h:150
cata::value_ptr< islot_book > book
Definition: itype.h:854
std::map< std::string, use_function > use_methods
Actions an instance can perform (if any) indexed by action type.
Definition: itype.h:925

References _, itype::book, BOOK_MORALECHANGE, BOOK_NUMUNREADCHAPTERS, BOOK_REQUIREMENTS_BEGINNER, BOOK_REQUIREMENTS_INT, BOOK_SKILLRANGE_MAX, BOOK_SKILLRANGE_MIN, BOOK_SUMMARY, BOOK_TIMEPERCHAPTER, BOOK_UNREAD, SkillLevel::can_train(), itype::can_use(), islot_book::chapters, DESCRIPTION_BOOK_ADDITIONAL_RECIPES, DESCRIPTION_BOOK_RECIPES, enumerate_as_string(), get_avatar(), character_funcs::get_book_fun_for(), get_player_character(), get_remaining_chapters(), Character::get_skill_level(), Character::get_skill_level_object(), avatar::has_identified(), info(), insert_separation_line(), islot_book::intel, is_book(), islot_book::recipe_with_description_t::is_hidden(), Character::knows_recipe(), islot_book::level, SkillLevel::level(), iteminfo::lower_is_better, martial_art_learned_from(), martialart_difficulty(), islot_book::recipe_with_description_t::name, martialart::name, Skill::name(), om_direction::name(), iteminfo::no_flags, string_id< T >::obj(), martialart::primary_skill, islot_book::recipe_with_description_t::recipe, islot_book::recipes, islot_book::req, recipe::result_name(), iteminfo::show_plus, islot_book::skill, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, string_format(), iteminfo_query::test(), islot_book::time, type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ brewing_results()

const std::vector< itype_id > & item::brewing_results ( ) const

The results of fermenting this item.

Definition at line 5959 of file item.cpp.

5960{
5961 static const std::vector<itype_id> nulresult{};
5962 return is_brewable() ? type->brewable->results : nulresult;
5963}
bool is_brewable() const
Definition: item.cpp:6611
cata::value_ptr< islot_brewable > brewable
Definition: itype.h:851

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ brewing_time()

time_duration item::brewing_time ( ) const

Time for this item to be fully fermented.

Definition at line 5954 of file item.cpp.

5955{
5956 return is_brewable() ? type->brewable->time : 0_turns;
5957}

References itype::brewable, is_brewable(), and type.

Referenced by final_info(), and iexamine::fvat_full().

◆ bullet_resist()

int item::bullet_resist ( bool  to_self = false) const

Definition at line 6106 of file item.cpp.

6107{
6108 if( is_null() ) {
6109 return 0;
6110 }
6111
6112 const int base_thickness = get_thickness();
6113 float resist = 0;
6115 int eff_thickness = 1;
6116
6117 // base resistance
6118 // Don't give reinforced items +armor, just more resistance to ripping
6119 const int dmg = damage_level( 4 );
6120 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6121 eff_thickness = std::max( 1, base_thickness - eff_damage );
6122
6123 const std::vector<const material_type *> mat_types = made_of_types();
6124 if( !mat_types.empty() ) {
6125 for( const material_type *mat : mat_types ) {
6126 resist += mat->bullet_resist();
6127 }
6128 // Average based on number of materials.
6129 resist /= mat_types.size();
6130 }
6131
6132 return std::lround( ( resist * eff_thickness ) + mod );
6133}
@ clothing_mod_type_bullet
Definition: clothing_mod.h:21

References clothing_mod_type_bullet, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ burn()

bool item::burn ( fire_data frd)

Burns the item.

Returns true if the item was destroyed.

Definition at line 8292 of file item.cpp.

8293{
8294 float burn_added = simulate_burn( frd );
8295
8296 if( burn_added <= 0 ) {
8297 return false;
8298 }
8299
8300 if( count_by_charges() ) {
8301 if( type->volume == 0_ml ) {
8302 charges = 0;
8303 } else {
8305 ( 3.0 * type->volume ) );
8306 }
8307
8308 return charges <= 0;
8309 }
8310
8311 if( is_corpse() ) {
8312 const mtype *mt = get_mtype();
8313 if( active && mt != nullptr && burnt + burn_added > mt->hp &&
8314 !mt->burn_into.is_null() && mt->burn_into.is_valid() ) {
8315 corpse = &get_mtype()->burn_into.obj();
8316 // Delay rezing
8317 set_age( 0_turns );
8318 burnt = 0;
8319 return false;
8320 }
8321 }
8322
8323 burnt += roll_remainder( burn_added );
8324
8325 const int vol = base_volume() / units::legacy_volume_factor;
8326 return burnt >= vol * 3;
8327}
units::volume base_volume() const
Simplified, faster volume check for when processing time is important and exact volume is not.
Definition: item.cpp:5084
float simulate_burn(fire_data &frd) const
Calculate all burning calculations, but don't actually apply them to item.
Definition: item.cpp:8239
const mtype * get_mtype() const
Definition: item.cpp:6633
void set_age(const time_duration &age)
Definition: item.cpp:10031
bool is_valid() const
Returns whether this id is valid, that means whether it refers to an existing object.
Definition: achievement.cpp:67
static constexpr volume legacy_volume_factor
Definition: units_volume.h:50
int roll_remainder(double value)
Definition: rng.cpp:96
Definition: mtype.h:208
mtype_id burn_into
Definition: mtype.h:331
int hp
Definition: mtype.h:270

References active, base_volume(), mtype::burn_into, burnt, charges, corpse, count_by_charges(), get_mtype(), mtype::hp, is_corpse(), string_id< T >::is_null(), string_id< T >::is_valid(), units::legacy_volume_factor, string_id< T >::obj(), roll_remainder(), set_age(), simulate_burn(), itype::stack_size, type, and itype::volume.

Referenced by Character::absorb_hit().

◆ calc_rot()

time_duration item::calc_rot ( time_point  time,
int  temp 
) const

Returns rot of the item since last rot calculation.

This function should not be called directly. since it does not have all the needed checks or temperature calculations. If you need to calc rot of item call process_rot instead.

Parameters
timeTime point to which rot is calculated
tempTemperature at which the rot is calculated

Definition at line 5659 of file item.cpp.

5660{
5661 // Avoid needlessly calculating already rotten things. Corpses should
5662 // always rot away and food rots away at twice the shelf life. If the food
5663 // is in a sealed container they won't rot away, this avoids needlessly
5664 // calculating their rot in that case.
5665 if( !is_corpse() && get_relative_rot() > 2.0 ) {
5666 return time_duration::from_seconds( 0 );
5667 }
5668
5669 // rot modifier
5670 float factor = 1.0;
5671 if( is_corpse() && has_flag( flag_FIELD_DRESS ) ) {
5672 factor = 0.75;
5673 }
5674
5676 // simulation of different age of food at the start of the game and good/bad storage
5677 // conditions by applying starting variation bonus/penalty of +/- 20% of base shelf-life
5678 // positive = food was produced some time before calendar::start and/or bad storage
5679 // negative = food was stored in good conditions before calendar::start
5681 time_duration spoil_variation = get_shelf_life() * 0.2f;
5682 added_rot += rng( -spoil_variation, spoil_variation );
5683 }
5684
5685 time_duration time_delta = time - last_rot_check;
5686 added_rot += factor * time_delta / 1_hours * get_hourly_rotpoints_at_temp( temp ) * 1_turns;
5687 return added_rot;
5688}
A duration defined as a number of specific time units.
Definition: calendar.h:180
static constexpr time_duration from_seconds(const T t)
Definition: calendar.h:208
static const std::string flag_FIELD_DRESS("FIELD_DRESS")
int get_hourly_rotpoints_at_temp(const int temp)
Get the hourly rot for a given temperature from the precomputed table.
Definition: item.cpp:5643
@ time
Recharges slowly with time.

References flag_FIELD_DRESS(), time_duration::from_seconds(), get_hourly_rotpoints_at_temp(), get_relative_rot(), get_shelf_life(), has_flag(), is_corpse(), last_rot_check, rng(), calendar::start_of_cataclysm, and time.

Referenced by process_rot().

◆ can_contain() [1/2]

bool item::can_contain ( const item it) const

Can this item have given item/itype as content?

For example, airtight for gas, acidproof for acid etc.

Definition at line 7038 of file item.cpp.

7039{
7040 // TODO: Volume check
7041 return can_contain( *it.type );
7042}
bool can_contain(const item &it) const
Can this item have given item/itype as content?
Definition: item.cpp:7038

References can_contain(), and type.

Referenced by can_contain().

◆ can_contain() [2/2]

bool item::can_contain ( const itype tp) const

Definition at line 7044 of file item.cpp.

7045{
7046 if( !type->container ) {
7047 // TODO: Tools etc.
7048 return false;
7049 }
7050
7051 if( tp.phase == LIQUID && !type->container->watertight ) {
7052 return false;
7053 }
7054
7055 // TODO: Acid in waterskins
7056 return true;
7057}
@ LIQUID
Definition: enums.h:175
phase_id phase
Definition: itype.h:942

References itype::container, LIQUID, itype::phase, and type.

◆ can_holster()

bool item::can_holster ( const item obj,
bool  ignore = false 
) const

Checks if item is a holster and currently capable of storing obj.

Parameters
objobject that we want to holster
ignoreonly check item is compatible and ignore any existing contents

Definition at line 8885 of file item.cpp.

8886{
8887 if( !type->can_use( "holster" ) ) {
8888 return false; // item is not a holster
8889 }
8890
8891 const holster_actor *ptr = dynamic_cast<const holster_actor *>
8892 ( type->get_use( "holster" )->get_actor_ptr() );
8893 if( !ptr->can_holster( obj ) ) {
8894 return false; // item is not a suitable holster for obj
8895 }
8896
8897 if( !ignore && static_cast<int>( contents.num_item_stacks() ) >= ptr->multi ) {
8898 return false; // item is already full
8899 }
8900
8901 return true;
8902}
Holster a weapon.
Definition: iuse_actor.h:842
size_t num_item_stacks() const
returns the number of items stacks in contents each item that is not count_by_charges,...
const void * ptr(const T *p)
\rst Converts p to const void* for pointer formatting.

References itype::can_use(), contents, use_function::get_actor_ptr(), itype::get_use(), item_contents::num_item_stacks(), ptr(), and type.

◆ can_reload_with() [1/2]

bool item::can_reload_with ( const ammotype ammo) const

Returns true if this item can be reloaded with specified ammo type, ignoring currently loaded ammo.

Definition at line 6869 of file item.cpp.

6870{
6871 return is_reloadable_helper( ammo->default_ammotype(), false );
6872}
bool is_reloadable_helper(const itype_id &ammo, bool now) const
Helper for checking reloadability.
Definition: item.cpp:6884

References ammunition_type::default_ammotype(), and is_reloadable_helper().

Referenced by favorite_ammo_or_select(), avatar_funcs::gunmod_add(), and aim_activity_actor::load_RAS_weapon().

◆ can_reload_with() [2/2]

bool item::can_reload_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo item, ignoring currently loaded ammo.

Definition at line 6874 of file item.cpp.

6875{
6876 return is_reloadable_helper( ammo, false );
6877}

References is_reloadable_helper().

◆ can_revive()

bool item::can_revive ( ) const

Whether this is a corpse that can be revived.

Definition at line 5965 of file item.cpp.

5966{
5967 return is_corpse() && corpse->has_flag( MF_REVIVES ) && damage() < max_damage() &&
5971}
int max_damage() const
Maximum amount of damage to an item (state before destroyed)
Definition: item.cpp:6224
static const std::string flag_QUARTERED("QUARTERED")
static const std::string flag_SKINNED("SKINNED")
static const std::string flag_FIELD_DRESS_FAILED("FIELD_DRESS_FAILED")
static const std::string flag_PULPED("PULPED")
@ MF_REVIVES
Definition: mtype.h:125
bool has_flag(m_flag flag) const
Definition: mtype.cpp:75

References corpse, damage(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_PULPED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), mtype::has_flag(), is_corpse(), max_damage(), and MF_REVIVES.

Referenced by active_item_cache::add(), color_in_inventory(), has_rotten_away(), ready_to_revive(), active_item_cache::remove(), basecamp::start_relay_hide_site(), and basecamp::start_setup_hide_site().

◆ can_unload_liquid()

bool item::can_unload_liquid ( ) const

Returns true if not empty if it's liquid, it's not currently frozen in resealable container.

Definition at line 6858 of file item.cpp.

6859{
6860 if( is_container_empty() ) {
6861 return true;
6862 }
6863
6864 const item &cts = contents.front();
6865 bool cts_is_frozen_liquid = cts.made_of( LIQUID ) && cts.made_of( SOLID );
6866 return is_bucket() || !cts_is_frozen_liquid;
6867}
const std::vector< material_id > & made_of() const
The ids of all the materials this is made of.
Definition: item.cpp:6421
bool is_container_empty() const
Whether this item has no contents at all.
Definition: item.cpp:6845
bool is_bucket() const
Definition: item.cpp:6742
@ SOLID
Definition: enums.h:175

References contents, item_contents::front(), is_bucket(), is_container_empty(), LIQUID, made_of(), and SOLID.

Referenced by item_funcs::can_be_unloaded(), iexamine::keg(), and avatar_funcs::unload_item().

◆ casings_count()

int item::casings_count ( ) const

How many spent casings are contained within this item?

Definition at line 8098 of file item.cpp.

8099{
8100 int res = 0;
8101
8102 const_cast<item *>( this )->casings_handle( [&res]( item & ) {
8103 ++res;
8104 return false;
8105 } );
8106
8107 return res;
8108}
void casings_handle(const std::function< bool(item &)> &func)
Apply predicate to each contained spent casing removing it if predicate returns true.
Definition: item.cpp:8110

References casings_handle().

Referenced by item_funcs::can_be_unloaded(), and avatar_funcs::unload_item().

◆ casings_handle()

void item::casings_handle ( const std::function< bool(item &)> &  func)

Apply predicate to each contained spent casing removing it if predicate returns true.

Definition at line 8110 of file item.cpp.

8111{
8112 if( !is_gun() ) {
8113 return;
8114 }
8115
8116 contents.casings_handle( func );
8117}
void casings_handle(const std::function< bool(item &)> &func)

References item_contents::casings_handle(), contents, and is_gun().

Referenced by casings_count(), avatar_funcs::gunmod_remove(), reload(), and avatar_funcs::unload_item().

◆ charges_per_volume()

int item::charges_per_volume ( const units::volume vol) const

Number of (charges of) this item that fit into the given volume.

May return 0 if not even one charge fits into the volume. Only depends on the type of this item not on its current charge count.

For items not counted by charges, this returns vol / this->volume().

Definition at line 867 of file item.cpp.

868{
869 if( count_by_charges() ) {
870 if( type->volume == 0_ml ) {
871 debugmsg( "Item '%s' with zero volume", tname() );
872 return INFINITE_CHARGES;
873 }
874 // Type cast to prevent integer overflow with large volume containers like the cargo
875 // dimension
876 return vol * static_cast<int64_t>( type->stack_size ) / type->volume;
877 } else {
878 units::volume my_volume = volume();
879 if( my_volume == 0_ml ) {
880 debugmsg( "Item '%s' with zero volume", tname() );
881 return INFINITE_CHARGES;
882 }
883 return vol / my_volume;
884 }
885}
static const int INFINITE_CHARGES
Definition: item.h:2162

References count_by_charges(), debugmsg, INFINITE_CHARGES, itype::stack_size, tname(), type, volume(), and itype::volume.

Referenced by item_stack::amount_can_fit(), Character::can_feed_furnace_with(), vehicle_part::consume_energy(), display_name(), Character::feed_furnace_with(), activity_handlers::fill_liquid_do_turn(), Character::get_acquirable_energy(), get_remaining_capacity_for_liquid(), in_container(), Item_factory::migrate_item(), Item_modifier::modify(), vehicle::print_fuel_indicator(), advanced_inventory::query_charges(), and try_fuel_fire().

◆ chip_resistance()

int item::chip_resistance ( bool  worst = false) const

Returns resistance to being damaged by attack against the item itself.

Calculated from item's materials.

Parameters
worstIf this is true, the worst resistance is used. Otherwise the best one.

Definition at line 6200 of file item.cpp.

6201{
6202 int res = worst ? INT_MAX : INT_MIN;
6203 for( const material_type *mat : made_of_types() ) {
6204 const int val = mat->chip_resist();
6205 res = worst ? std::min( res, val ) : std::max( res, val );
6206 }
6207
6208 if( res == INT_MAX || res == INT_MIN ) {
6209 return 2;
6210 }
6211
6212 if( res <= 0 ) {
6213 return 0;
6214 }
6215
6216 return res;
6217}

References made_of_types().

Referenced by Character::handle_melee_wear().

◆ clear_vars()

void item::clear_vars ( )

Removes all item variables.

Definition at line 1088 of file item.cpp.

1089{
1090 item_vars.clear();
1091}

References item_vars.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ color()

nc_color item::color ( ) const

Returns the default color of the item (e.g.

itype::color).

Definition at line 4918 of file item.cpp.

4919{
4920 if( is_null() ) {
4921 return c_black;
4922 }
4923 if( is_corpse() ) {
4924 return corpse->color;
4925 }
4926 return type->color;
4927}
#define c_black
Definition: color.h:17
nc_color color
Definition: itype.h:1006
nc_color color
Definition: mtype.h:261

References c_black, itype::color, mtype::color, corpse, is_corpse(), is_null(), and type.

Referenced by map::draw_maptile(), Character::pour_into(), and debug_menu::wishitem().

◆ color_in_inventory() [1/2]

nc_color item::color_in_inventory ( ) const

Returns the color of the item depending on usefulness for the player character, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Definition at line 4130 of file item.cpp.

4131{
4133}
nc_color color_in_inventory() const
Returns the color of the item depending on usefulness for the player character, e....
Definition: item.cpp:4130

References color_in_inventory(), and get_avatar().

Referenced by color_in_inventory(), colorized_item_name(), inventory_selector_preset::get_color(), read_inventory_preset::get_color(), avatar_funcs::gunmod_add(), game::list_items(), iuse::marloss_seed(), pickup::pick_up(), iuse::seed(), Character::takeoff(), and Character::will_eat().

◆ color_in_inventory() [2/2]

nc_color item::color_in_inventory ( const player p) const

Returns the color of the item depending on usefulness for the passed player, e.g.

differently if it its an unread book or a spoiling food item etc. This should only be used for displaying data, it should not affect game play.

Parameters
for_playerNPC or avatar which would read book.

Definition at line 4135 of file item.cpp.

4136{
4137 // Only item not otherwise colored gets colored as favorite
4139 if( type->can_use( "learn_spell" ) ) {
4140 const use_function *iuse = get_use( "learn_spell" );
4141 const learn_spell_actor *actor_ptr =
4142 static_cast<const learn_spell_actor *>( iuse->get_actor_ptr() );
4143 for( const std::string &spell_id_str : actor_ptr->spells ) {
4144 const spell_id sp_id( spell_id_str );
4145 if( p.magic->knows_spell( sp_id ) && !p.magic->get_spell( sp_id ).is_max_level() ) {
4146 ret = c_yellow;
4147 }
4148 if( !p.magic->knows_spell( sp_id ) && p.magic->can_learn_spell( p, sp_id ) ) {
4149 return c_light_blue;
4150 }
4151 }
4152 } else if( has_flag( flag_WET ) ) {
4153 ret = c_cyan;
4154 } else if( has_flag( flag_LITCIG ) ) {
4155 ret = c_red;
4156 } else if( is_armor() && p.has_trait( trait_WOOLALLERGY ) &&
4157 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
4158 ret = c_red;
4159 } else if( is_filthy() || has_own_flag( "DIRTY" ) ) {
4160 ret = c_brown;
4161 } else if( is_bionic() ) {
4162 if( !p.has_bionic( type->bionic->id ) ) {
4163 ret = p.bionic_installation_issues( type->bionic->id ).empty() ? c_green : c_red;
4164 } else if( !has_fault( fault_bionic_nonsterile ) ) {
4165 ret = c_dark_gray;
4166 }
4167 } else if( has_flag( flag_LEAK_DAM ) && has_flag( flag_RADIOACTIVE ) && damage() > 0 ) {
4169 } else if( active && !is_food() && !is_food_container() && !is_corpse() ) {
4170 // Active items show up as yellow
4171 ret = c_yellow;
4172 } else if( is_corpse() && can_revive() ) {
4173 // Only reviving corpses are yellow
4174 ret = c_yellow;
4175 } else if( const item *food = get_food() ) {
4176 const bool preserves = type->container && type->container->preserves;
4177
4178 // Give color priority to allergy (allergy > inedible by freeze or other conditions)
4179 // TODO: refactor u.will_eat to let this section handle coloring priority without duplicating code.
4180 if( p.allergy_type( *food ) != morale_type( "morale_null" ) ) {
4181 return c_red;
4182 }
4183
4184 // Default: permafood, drugs
4185 // Brown: rotten (for non-saprophages) or non-rotten (for saprophages)
4186 // Dark gray: inedible
4187 // Red: morale penalty
4188 // Yellow: will rot soon
4189 // Cyan: will rot eventually
4190 const ret_val<edible_rating> rating = p.will_eat( *food );
4191 // TODO: More colors
4192 switch( rating.value() ) {
4195 if( preserves ) {
4196 // Nothing, canned food won't rot
4197 } else if( food->is_going_bad() ) {
4198 ret = c_yellow;
4199 } else if( food->goes_bad() ) {
4200 ret = c_cyan;
4201 }
4202 break;
4205 ret = c_dark_gray;
4206 break;
4210 ret = c_red;
4211 break;
4213 ret = c_brown;
4214 break;
4217 ret = c_pink;
4218 break;
4220 break;
4221 }
4222 } else if( is_gun() ) {
4223 // Guns are green if you are carrying ammo for them
4224 // ltred if you have ammo but no mags
4225 // Gun with integrated mag counts as both
4226 for( const ammotype &at : ammo_types() ) {
4227 // get_ammo finds uncontained ammo, find_ammo finds ammo in magazines
4228 bool has_ammo = !character_funcs::get_ammo_items( p, at ).empty() ||
4229 !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4230 bool has_mag = magazine_integral() ||
4231 !character_funcs::find_ammo_items_or_mags( p, *this, true, -1 ).empty();
4232 if( has_ammo && has_mag ) {
4233 ret = c_green;
4234 break;
4235 } else if( has_ammo || has_mag ) {
4236 ret = c_light_red;
4237 break;
4238 }
4239 }
4240 } else if( is_ammo() ) {
4241 // Likewise, ammo is green if you have guns that use it
4242 // ltred if you have the gun but no mags
4243 // Gun with integrated mag counts as both
4244 bool has_gun = p.has_item_with( [this]( const item & i ) {
4245 return i.is_gun() && i.ammo_types().count( ammo_type() );
4246 } );
4247 bool has_mag = p.has_item_with( [this]( const item & i ) {
4248 return ( i.is_gun() && i.magazine_integral() && i.ammo_types().count( ammo_type() ) ) ||
4249 ( i.is_magazine() && i.ammo_types().count( ammo_type() ) );
4250 } );
4251 if( has_gun && has_mag ) {
4252 ret = c_green;
4253 } else if( has_gun || has_mag ) {
4254 ret = c_light_red;
4255 }
4256 } else if( is_magazine() ) {
4257 // Magazines are green if you have guns and ammo for them
4258 // ltred if you have one but not the other
4259 bool has_gun = p.has_item_with( [this]( const item & it ) {
4260 return it.is_gun() && it.magazine_compatible().count( typeId() ) > 0;
4261 } );
4262 bool has_ammo = !character_funcs::find_ammo_items_or_mags( p, *this, false, -1 ).empty();
4263 if( has_gun && has_ammo ) {
4264 ret = c_green;
4265 } else if( has_gun || has_ammo ) {
4266 ret = c_light_red;
4267 }
4268 } else if( is_book() ) {
4269 const islot_book &tmp = *type->book;
4270 // Player doesn't actually interested if NPC has identified book yet.
4271 // So we check identification for human avatar.
4272 if( get_avatar().has_identified( typeId() ) ) {
4273 if( tmp.skill && // Book can improve skill: blue
4275 p.get_skill_level( tmp.skill ) >= tmp.req &&
4276 p.get_skill_level( tmp.skill ) < tmp.level ) {
4277 ret = c_light_blue;
4278 } else if( type->can_use( "MA_MANUAL" ) &&
4279 !p.martial_arts_data->has_martialart( martial_art_learned_from( *type ) ) ) {
4280 ret = c_light_blue;
4281 } else if( tmp.skill && // Book can't improve skill right now, but maybe later: pink
4283 p.get_skill_level( tmp.skill ) < tmp.level ) {
4284 ret = c_pink;
4285 } else if( !p.studied_all_recipes(
4286 *type ) ) { // Book can't improve skill anymore, but has more recipes: yellow
4287 ret = c_yellow;
4288 }
4289 } else if( tmp.skill || type->can_use( "MA_MANUAL" ) ) {
4290 // Book can teach you something and hasn't been identified yet
4291 ret = c_red;
4292 } else {
4293 // "just for fun" book that they haven't read yet
4294 ret = c_magenta;
4295 }
4296 }
4297 return ret;
4298}
morale_type allergy_type(const item &food) const
Returns allergy type or MORALE_NULL if not allergic for this character.
pimpl< character_martial_arts > martial_arts_data
Definition: character.h:1588
ret_val< edible_rating > will_eat(const item &food, bool interactive=false) const
Same as can_eat, but takes consequences into account.
bool has_bionic(const bionic_id &b) const
Returns true if the player has the entered bionic id.
Definition: character.cpp:1812
std::map< bodypart_id, int > bionic_installation_issues(const bionic_id &bioid) const
Definition: bionics.cpp:2574
bool has_trait(const trait_id &b) const override
Returns true if the player has the entered trait.
Definition: mutation.cpp:101
pimpl< known_magic > magic
Definition: character.h:1485
bool is_favorite
Definition: item.h:2243
std::set< itype_id > magazine_compatible(bool conversion=true) const
Get compatible magazines (if any) for this item.
Definition: item.cpp:7709
bool has_fault(const fault_id &fault) const
Does this item have the specified fault.
Definition: item.cpp:5301
bool is_filthy() const
Marks the item as filthy, so characters with squeamish trait can't wear it.
Definition: item.cpp:10002
bool is_food_container() const
Definition: item.cpp:6616
const use_function * get_use(const std::string &use_name) const
Returns the pointer to use_function with name use_name assigned to the type of this item or any of it...
Definition: item.cpp:7956
bool can_revive() const
Whether this is a corpse that can be revived.
Definition: item.cpp:5965
bool has_own_flag(const std::string &flag) const
Checks whether item itself has given flag (doesn't check item type or gunmods).
Definition: item.cpp:5306
Learn a spell.
Definition: iuse_actor.h:799
std::vector< std::string > spells
Definition: iuse_actor.h:802
bool studied_all_recipes(const itype &book) const
Definition: player.cpp:264
The class represents a composite return value of an arbitrary function (result).
Definition: ret_val.h:21
T value() const
Definition: ret_val.h:74
bool has_item_with(const std::function< bool(const item &)> &filter) const
Returns true if any item (including those within a container) matches the filter.
Definition: visitable.cpp:104
#define c_white
Definition: color.h:18
#define c_light_gray
Definition: color.h:19
#define c_green
Definition: color.h:22
#define c_light_green
Definition: color.h:28
#define c_magenta
Definition: color.h:25
#define c_brown
Definition: color.h:26
#define c_dark_gray
Definition: color.h:20
#define c_pink
Definition: color.h:31
#define c_yellow
Definition: color.h:32
#define c_cyan
Definition: color.h:24
#define c_light_red
Definition: color.h:27
#define c_red
Definition: color.h:21
static const std::string flag_WET("WET")
static const trait_id trait_WOOLALLERGY("WOOLALLERGY")
static const fault_id fault_bionic_nonsterile("fault_bionic_nonsterile")
static const std::string flag_LEAK_DAM("LEAK_DAM")
static const std::string flag_LITCIG("LITCIG")
static const std::string flag_RADIOACTIVE("RADIOACTIVE")
std::vector< const item * > get_ammo_items(const Character &who, const ammotype &at)
Returns character's items that are ammo and have the matching ammo type.
std::vector< item_location > find_ammo_items_or_mags(const Character &who, const item &obj, bool empty, int radius)
Searches for ammo or magazines that can be used to reload given item.
Definition: iuse.h:25
string_id< material_type > material_id
Definition: type_id.h:95

References active, allergy, Character::allergy_type(), allergy_weak, ammo_type(), ammo_types(), itype::bionic, Character::bionic_installation_issues(), bloated, itype::book, c_brown, c_cyan, c_dark_gray, c_green, c_light_blue, c_light_gray, c_light_green, c_light_red, c_magenta, c_pink, c_red, c_white, c_yellow, can_revive(), SkillLevel::can_train(), itype::can_use(), cannibalism, itype::container, damage(), edible, fault_bionic_nonsterile, character_funcs::find_ammo_items_or_mags(), flag_LEAK_DAM(), flag_LITCIG(), flag_RADIOACTIVE(), flag_WET(), character_funcs::get_ammo_items(), get_avatar(), get_food(), Character::get_skill_level(), Character::get_skill_level_object(), get_use(), Character::has_bionic(), has_fault(), has_flag(), visitable< T >::has_item_with(), has_own_flag(), Character::has_trait(), inedible, inedible_mutation, is_ammo(), is_armor(), is_bionic(), is_book(), is_corpse(), is_favorite, is_filthy(), is_food(), is_food_container(), is_gun(), is_magazine(), islot_book::level, made_of(), magazine_compatible(), magazine_integral(), Character::magic, martial_art_learned_from(), Character::martial_arts_data, nausea, no_tool, islot_book::req, cata::hash64_detail::ret, rotten, islot_book::skill, learn_spell_actor::spells, player::studied_all_recipes(), too_full, trait_WOOLALLERGY, type, typeId(), ret_val< T >::value(), and Character::will_eat().

◆ combat_info()

void item::combat_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3401 of file item.cpp.

3403{
3404 const std::string space = " ";
3405
3406 int dmg_bash = damage_melee( DT_BASH );
3407 int dmg_cut = damage_melee( DT_CUT );
3408 int dmg_stab = damage_melee( DT_STAB );
3409 if( parts->test( iteminfo_parts::BASE_DAMAGE ) ) {
3411 std::string sep;
3412 if( dmg_bash || dmg_cut || dmg_stab ) {
3413 info.push_back( iteminfo( "BASE", _( "<bold>Melee damage</bold>: " ), "", iteminfo::no_newline ) );
3414 }
3415 if( dmg_bash ) {
3416 info.push_back( iteminfo( "BASE", _( "Bash: " ), "", iteminfo::no_newline, dmg_bash ) );
3417 sep = space;
3418 }
3419 if( dmg_cut ) {
3420 info.push_back( iteminfo( "BASE", sep + _( "Cut: " ), "", iteminfo::no_newline, dmg_cut ) );
3421 sep = space;
3422 }
3423 if( dmg_stab ) {
3424 info.push_back( iteminfo( "BASE", sep + _( "Pierce: " ), "", iteminfo::no_newline, dmg_stab ) );
3425 }
3426 }
3427
3428 if( dmg_bash || dmg_cut || dmg_stab ) {
3429 if( parts->test( iteminfo_parts::BASE_TOHIT ) ) {
3430 info.push_back( iteminfo( "BASE", space + _( "To-hit bonus: " ), "",
3432 }
3433
3434 if( parts->test( iteminfo_parts::BASE_MOVES ) ) {
3435 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "",
3437 info.emplace_back( "BASE", _( "Typical damage per second:" ), "" );
3438 const std::map<std::string, double> &dps_data = dps( true, false );
3439 std::string sep;
3440 for( const std::pair<const std::string, double> &dps_entry : dps_data ) {
3441 info.emplace_back( "BASE", sep + dps_entry.first + ": ", "",
3443 dps_entry.second );
3444 sep = space;
3445 }
3446 info.emplace_back( "BASE", "" );
3447 }
3448 }
3449
3451 std::set<matec_id> all_techniques = type->techniques;
3452 all_techniques.insert( techniques.begin(), techniques.end() );
3453
3454 if( !all_techniques.empty() ) {
3455 const std::vector<matec_id> all_tec_sorted = sorted_lex( all_techniques );
3457 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Techniques when wielded</bold>: " ) +
3458 enumerate_as_string( all_tec_sorted.begin(), all_tec_sorted.end(), []( const matec_id & tid ) {
3459 return string_format( "<stat>%s</stat>: <info>%s</info>", _( tid.obj().name ),
3460 _( tid.obj().description ) );
3461 } ) ) );
3462 }
3463 }
3464
3465 avatar &you = get_avatar();
3466 // display which martial arts styles character can use with this weapon
3468 const std::string valid_styles = you.martial_arts_data->enumerate_known_styles( typeId() );
3469 if( !valid_styles.empty() ) {
3471 info.push_back( iteminfo( "DESCRIPTION",
3472 _( "You know how to use this with these martial arts "
3473 "styles: " ) + valid_styles ) );
3474 }
3475 }
3476
3477 if( !is_gunmod() && has_flag( flag_REACH_ATTACK ) &&
3480 if( has_flag( flag_REACH3 ) ) {
3481 info.push_back( iteminfo( "DESCRIPTION",
3482 _( "* This item can be used to make <stat>long reach "
3483 "attacks</stat>." ) ) );
3484 } else {
3485 info.push_back( iteminfo( "DESCRIPTION",
3486 _( "* This item can be used to make <stat>reach "
3487 "attacks</stat>." ) ) );
3488 }
3489 }
3490
3491 if( ( dmg_bash || dmg_cut || dmg_stab || type->m_to_hit > 0 ) || debug_mode ) {
3492 damage_instance non_crit;
3493 you.roll_all_damage( false, non_crit, true, *this );
3494 damage_instance crit;
3495 you.roll_all_damage( true, crit, true, *this );
3496 int attack_cost = you.attack_cost( *this );
3499 info.push_back( iteminfo( "DESCRIPTION", _( "<bold>Average melee damage</bold>:" ) ) );
3500 }
3501 // Chance of critical hit
3503 info.push_back( iteminfo( "DESCRIPTION",
3504 string_format( _( "Critical hit chance <neutral>%d%% - %d%%</neutral>" ),
3505 static_cast<int>( you.crit_chance( 0, 100, *this ) *
3506 100 ),
3507 static_cast<int>( you.crit_chance( 100, 0, *this ) *
3508 100 ) ) ) );
3509 }
3510 // Bash damage
3512 // NOTE: Using "BASE" instead of "DESCRIPTION", so numerical formatting will work
3513 // (output.cpp:format_item_info does not interpolate <num> for DESCRIPTION info)
3514 info.push_back( iteminfo( "BASE", _( "Bashing: " ), "<num>", iteminfo::no_newline,
3515 non_crit.type_damage( DT_BASH ) ) );
3516 info.push_back( iteminfo( "BASE", space + _( "Critical bash: " ), "<num>", iteminfo::no_flags,
3517 crit.type_damage( DT_BASH ) ) );
3518 }
3519 // Cut damage
3520 if( ( non_crit.type_damage( DT_CUT ) > 0.0f || crit.type_damage( DT_CUT ) > 0.0f )
3522
3523 info.push_back( iteminfo( "BASE", _( "Cutting: " ), "<num>", iteminfo::no_newline,
3524 non_crit.type_damage( DT_CUT ) ) );
3525 info.push_back( iteminfo( "BASE", space + _( "Critical cut: " ), "<num>", iteminfo::no_flags,
3526 crit.type_damage( DT_CUT ) ) );
3527 }
3528 // Pierce/stab damage
3529 if( ( non_crit.type_damage( DT_STAB ) > 0.0f || crit.type_damage( DT_STAB ) > 0.0f )
3531
3532 info.push_back( iteminfo( "BASE", _( "Piercing: " ), "<num>", iteminfo::no_newline,
3533 non_crit.type_damage( DT_STAB ) ) );
3534 info.push_back( iteminfo( "BASE", space + _( "Critical pierce: " ), "<num>", iteminfo::no_flags,
3535 crit.type_damage( DT_STAB ) ) );
3536 }
3537 // Moves
3539 info.push_back( iteminfo( "BASE", _( "Moves per attack: " ), "<num>",
3541 }
3543 }
3544}
bool debug_mode
Extended debugging mode, can be toggled during game.
int attack_cost(const item &weap) const
Returns cost (in moves) of attacking with given item (no modifiers, like stuck)
Definition: melee.cpp:2279
double crit_chance(float roll_hit, float target_dodge, const item &weap) const
Returns the chance to critical given a hit roll and target's dodge roll.
Definition: melee.cpp:796
void roll_all_damage(bool crit, damage_instance &di, bool average, const item &weap) const
Adds all 3 types of physical damage to instance.
Definition: melee.cpp:411
int attack_cost() const
Base number of moves (Creature::moves) that a single melee attack with this items takes.
Definition: item.cpp:5189
@ DT_STAB
Definition: damage.h:27
@ DT_BASH
Definition: damage.h:24
@ DT_CUT
Definition: damage.h:25
static const std::string flag_REACH3("REACH3")
static const std::string flag_REACH_ATTACK("REACH_ATTACK")
@ DESCRIPTION_MELEEDMG_PIERCE
@ DESCRIPTION_GUNMOD_ADDREACHATTACK
@ DESCRIPTION_MELEEDMG_MOVES
@ DESCRIPTION_APPLICABLEMARTIALARTS
float type_damage(damage_type dt) const
Definition: damage.cpp:64
int m_to_hit
Definition: itype.h:998
std::set< matec_id > techniques
Definition: itype.h:933

References _, attack_cost(), Character::attack_cost(), BASE_DAMAGE, BASE_MOVES, BASE_TOHIT, Character::crit_chance(), damage_melee(), debug_mode, DESCRIPTION_APPLICABLEMARTIALARTS, DESCRIPTION_GUNMOD_ADDREACHATTACK, DESCRIPTION_MELEEDMG, DESCRIPTION_MELEEDMG_BASH, DESCRIPTION_MELEEDMG_CRIT, DESCRIPTION_MELEEDMG_CUT, DESCRIPTION_MELEEDMG_MOVES, DESCRIPTION_MELEEDMG_PIERCE, DESCRIPTION_TECHNIQUES, dps(), DT_BASH, DT_CUT, DT_STAB, enumerate_as_string(), flag_REACH3(), flag_REACH_ATTACK(), get_avatar(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, is_gunmod(), iteminfo::lower_is_better, itype::m_to_hit, Character::martial_arts_data, iteminfo::no_flags, iteminfo::no_newline, Character::roll_all_damage(), iteminfo::show_plus, sorted_lex(), sign::space, string_format(), techniques, itype::techniques, iteminfo_query::test(), type, damage_instance::type_damage(), and typeId().

Referenced by info().

◆ common_ammo_default()

itype_id item::common_ammo_default ( bool  conversion = true) const

Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists.

Parameters
conversionwhether to include the effect of any flags or mods which convert the type
Returns
itype_id of default ammo for the first ammotype common to an item and its current magazine or "NULL" if none exists

Definition at line 7625 of file item.cpp.

7626{
7627 if( !ammo_types( conversion ).empty() ) {
7628 for( const ammotype &at : ammo_types( conversion ) ) {
7629 const item *mag = magazine_current();
7630 if( mag && mag->type->magazine->type.count( at ) ) {
7631 itype_id res = at->default_ammotype();
7632 if( !res.is_empty() ) {
7633 return res;
7634 }
7635 }
7636 }
7637 }
7638 return itype_id::NULL_ID();
7639}

References ammo_types(), string_id< T >::is_empty(), itype::magazine, magazine_current(), string_id< itype >::NULL_ID(), and type.

Referenced by gun_info().

◆ component_info()

void item::component_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3132 of file item.cpp.

3134{
3136 return;
3137 }
3138 if( is_craft() ) {
3139 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Using: %s" ),
3140 _( components_to_string() ) ) ) );
3141 // Ugly hack warning! Corpses have CBMs as their components
3142 } else if( !is_corpse() ) {
3143 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Made from: %s" ),
3144 _( components_to_string() ) ) ) );
3145 } else if( get_var( "bionics_scanned_by", -1 ) == get_avatar().getID().get_value() ) {
3146 // TODO: Extract into a more proper place (function in namespace)
3147 std::string bionics_string = enumerate_as_string( components.begin(), components.end(),
3148 []( const item & entry ) -> std::string {
3149 return entry.is_bionic() ? entry.display_name() : "";
3151 info.push_back( iteminfo( "DESCRIPTION", string_format( _( "Contains: %s" ),
3152 bionics_string ) ) );
3153 }
3154}
std::string components_to_string() const
List of all components in printable form, empty if this item has no components.
Definition: item.cpp:8904
@ DESCRIPTION_COMPONENTS_MADEFROM

References _, components, components_to_string(), DESCRIPTION_COMPONENTS_MADEFROM, enumerate_as_string(), get_avatar(), get_var(), info(), is_corpse(), is_craft(), none, string_format(), and iteminfo_query::test().

Referenced by info().

◆ components_to_string()

std::string item::components_to_string ( ) const

List of all components in printable form, empty if this item has no components.

Definition at line 8904 of file item.cpp.

8905{
8906 using t_count_map = std::map<std::string, int>;
8907 t_count_map counts;
8908 for( const item &elem : components ) {
8909 if( !elem.has_flag( flag_BYPRODUCT ) ) {
8910 const std::string name = elem.display_name();
8911 counts[name]++;
8912 }
8913 }
8914 return enumerate_as_string( counts.begin(), counts.end(),
8915 []( const std::pair<std::string, int> &entry ) -> std::string {
8916 if( entry.second != 1 )
8917 {
8918 return string_format( pgettext( "components count", "%d x %s" ), entry.second, entry.first );
8919 } else
8920 {
8921 return entry.first;
8922 }
8924}
static const std::string flag_BYPRODUCT("BYPRODUCT")

References components, enumerate_as_string(), flag_BYPRODUCT(), and om_direction::name().

Referenced by component_info().

◆ conductive()

bool item::conductive ( ) const

Whether the items is conductive.

Definition at line 6486 of file item.cpp.

6487{
6488 if( is_null() ) {
6489 return false;
6490 }
6491
6492 if( has_flag( flag_CONDUCTIVE ) ) {
6493 return true;
6494 }
6495
6496 if( has_flag( flag_NONCONDUCTIVE ) ) {
6497 return false;
6498 }
6499
6500 // If any material has electricity resistance equal to or lower than flesh (1) we are conductive.
6501 const std::vector<const material_type *> &mats = made_of_types();
6502 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6503 return mt->elec_resist() <= 1;
6504 } );
6505}
static const std::string flag_CONDUCTIVE("CONDUCTIVE")
static const std::string flag_NONCONDUCTIVE("NONCONDUCTIVE")

References flag_CONDUCTIVE(), flag_NONCONDUCTIVE(), has_flag(), is_null(), and made_of_types().

Referenced by Character::block_hit(), final_info(), and mdefense::zapback().

◆ contain_monster()

int item::contain_monster ( const tripoint target)

Definition at line 9259 of file iuse.cpp.

9260{
9261 const monster *const mon_ptr = g->critter_at<monster>( target );
9262 if( !mon_ptr ) {
9263 return 0;
9264 }
9265 const monster &f = *mon_ptr;
9266
9267 set_var( "contained_json", ::serialize( f ) );
9268 set_var( "contained_name", f.type->nname() );
9269 set_var( "name", string_format( _( "%s holding %s" ), type->nname( 1 ),
9270 f.type->nname() ) );
9271 // Need to add the weight of the empty container because item::weight uses the "weight" variable directly.
9272 set_var( "weight", to_milligram( type->weight + f.get_weight() ) );
9273 g->remove_zombie( f );
9274 return 0;
9275}
void serialize(JsonOut &json) const
const mtype * type
Definition: monster.h:478
units::mass get_weight() const override
Definition: monster.cpp:2734
constexpr value_type to_milligram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:62
units::mass weight
Weight of item ( or each stack member )
Definition: itype.h:965
std::string nname(unsigned int quantity) const
Definition: itype.cpp:78
std::string nname(unsigned int quantity=1) const
Definition: mtype.cpp:65

References _, g, monster::get_weight(), itype::nname(), mtype::nname(), serialize(), set_var(), string_format(), units::to_milligram(), type, monster::type, and itype::weight.

Referenced by iuse::capture_monster_act().

◆ container_info()

void item::container_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3037 of file item.cpp.

3039{
3040 if( !is_container() || !parts->test( iteminfo_parts::CONTAINER_DETAILS ) ) {
3041 return;
3042 }
3043
3045 const islot_container &c = *type->container;
3046
3047 std::string container_str = _( "This container " );
3048
3049 if( c.seals ) {
3050 container_str += _( "can be <info>resealed</info>, " );
3051 }
3052 if( c.watertight ) {
3053 container_str += _( "is <info>watertight</info>, " );
3054 }
3055 if( c.preserves ) {
3056 container_str += _( "<good>prevents spoiling</good>, " );
3057 }
3058
3059 container_str += string_format( _( "can store <info>%s %s</info>." ),
3060 format_volume( c.contains ), volume_units_long() );
3061
3062 info.push_back( iteminfo( "CONTAINER", container_str ) );
3063}
bool is_container() const
Whether this is container.
Definition: item.cpp:6727
std::string format_volume(const units::volume &volume)
Convert, round up and format a volume.
Definition: output.cpp:2020
const char * volume_units_long()
Create a units label for a volume value.

References _, c, itype::container, CONTAINER_DETAILS, format_volume(), info(), insert_separation_line(), is_container(), string_format(), iteminfo_query::test(), type, and volume_units_long().

Referenced by info().

◆ contents_info()

void item::contents_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3546 of file item.cpp.

3548{
3550 return;
3551 }
3552 const std::string space = " ";
3553
3554 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
3555 std::string mod_str;
3556 if( mod->type->gunmod ) {
3557 if( mod->is_irremovable() ) {
3558 mod_str = _( "Integrated mod: " );
3559 } else {
3560 mod_str = _( "Mod: " );
3561 }
3562 mod_str += string_format( "<bold>%s</bold> (%s) ", mod->tname(),
3563 mod->type->gunmod->location.name() );
3564 }
3566 info.emplace_back( "DESCRIPTION", mod_str );
3567 info.emplace_back( "DESCRIPTION", mod->type->description.translated() );
3568 }
3569 bool contents_header = false;
3570 for( const item *contents_item : contents.all_items_top() ) {
3571 if( !contents_item->type->mod ) {
3572 if( !contents_header ) {
3574 info.emplace_back( "DESCRIPTION", _( "<bold>Contents of this item</bold>:" ) );
3575 contents_header = true;
3576 } else {
3577 // Separate items with a blank line
3578 info.emplace_back( "DESCRIPTION", space );
3579 }
3580
3581 const translation &description = contents_item->type->description;
3582
3583 if( contents_item->made_of( LIQUID ) ) {
3584 units::volume contents_volume = contents_item->volume() * batch;
3585 int converted_volume_scale = 0;
3586 const double converted_volume =
3587 round_up( convert_volume( contents_volume.value(),
3588 &converted_volume_scale ), 2 );
3589 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3591 if( display_mod_source ) {
3592 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3593 enumerate_as_string( contents_item->type->src.begin(),
3594 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3595 return string_format( "'%s'", content_source.second->name() );
3597 }
3598 if( display_object_ids ) {
3599 info.emplace_back( "DESCRIPTION", colorize(
3600 string_format( "[%s]", contents_item->type->get_id() ),
3601 c_light_blue ) );
3602 }
3603 if( converted_volume_scale != 0 ) {
3605 }
3606 info.emplace_back( "CONTAINER", description + space,
3607 string_format( "<num> %s", volume_units_abbr() ), f,
3608 converted_volume );
3609 } else {
3610 info.emplace_back( "DESCRIPTION", contents_item->display_name() );
3611 if( display_mod_source ) {
3612 info.emplace_back( "DESCRIPTION", string_format( _( "<stat>Origin: %s</stat>" ),
3613 enumerate_as_string( contents_item->type->src.begin(),
3614 contents_item->type->src.end(), []( const std::pair<itype_id, mod_id> &content_source ) {
3615 return string_format( "'%s'", content_source.second->name() );
3617 }
3618 if( display_object_ids ) {
3619 info.emplace_back( "DESCRIPTION", colorize(
3620 string_format( "[%s]", contents_item->type->get_id() ),
3621 c_light_blue ) );
3622 }
3623 info.emplace_back( "DESCRIPTION", description.translated() );
3624 }
3625 }
3626 }
3627}
Class for storing translation context and raw string for deferred translation.
Definition: translations.h:152
constexpr const value_type & value() const
Access the raw dimensionless value.
Definition: units_def.h:44

References _, item_contents::all_items_top(), arrow, c_light_blue, colorize(), contents, convert_volume(), DESCRIPTION_CONTENTS, display_mod_source, display_object_ids, item_contents::empty(), enumerate_as_string(), gunmods(), info(), insert_separation_line(), iteminfo::is_decimal, is_gun(), LIQUID, iteminfo::no_newline, round_up(), sign::space, string_format(), iteminfo_query::test(), toolmods(), translation::translated(), units::quantity< V, U >::value(), and volume_units_abbr().

Referenced by info().

◆ contents_made_of()

bool item::contents_made_of ( phase_id  phase) const

If contents nonempty, return true if item phase is same, else false.

Definition at line 6473 of file item.cpp.

6474{
6475 return !contents.empty() && contents.front().made_of( phase );
6476}

References contents, item_contents::empty(), item_contents::front(), and made_of().

Referenced by character_funcs::find_ammo_helper().

◆ contextualize_skill()

skill_id item::contextualize_skill ( const skill_id id) const

Puts the skill in context of the item.

Definition at line 9987 of file item.cpp.

9988{
9989 if( id->is_contextual_skill() ) {
9990 if( id == skill_weapon ) {
9991 if( is_gun() ) {
9992 return gun_skill();
9993 } else if( is_melee() ) {
9994 return melee_skill();
9995 }
9996 }
9997 }
9998
9999 return id;
10000}
skill_id gun_skill() const
The skill used to operate the gun.
Definition: item.cpp:7195
skill_id melee_skill() const
The most relevant skill used with this melee weapon.
Definition: item.cpp:7216
bool is_melee() const
Is this item an effective melee weapon for any damage type?
Definition: item.cpp:6675
static const skill_id skill_weapon("weapon")
const std::string id
Definition: basecamp.h:87

References gun_skill(), base_camps::id, is_gun(), is_melee(), melee_skill(), and skill_weapon.

Referenced by Character::enumerate_unmet_requirements(), and SkillLevelMap::get_skill_level().

◆ convert()

◆ corpse_volume()

units::volume item::corpse_volume ( const mtype corpse) const

Volume check for corpses, helper for base_volume().

Definition at line 5062 of file item.cpp.

5063{
5065 if( has_flag( flag_QUARTERED ) ) {
5066 corpse_volume /= 4;
5067 }
5069 corpse_volume *= 0.75;
5070 }
5071 if( has_flag( flag_GIBBED ) ) {
5072 corpse_volume *= 0.85;
5073 }
5074 if( has_flag( flag_SKINNED ) ) {
5075 corpse_volume *= 0.85;
5076 }
5077 if( corpse_volume > 0_ml ) {
5078 return corpse_volume;
5079 }
5080 debugmsg( "invalid monster volume for corpse" );
5081 return 0_ml;
5082}
static const std::string flag_GIBBED("GIBBED")
units::volume volume
Definition: mtype.h:263

References corpse, corpse_volume(), debugmsg, flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_QUARTERED(), flag_SKINNED(), has_flag(), and mtype::volume.

Referenced by base_volume(), corpse_volume(), and volume().

◆ count()

◆ count_by_charges() [1/2]

bool item::count_by_charges ( ) const

Definition at line 6013 of file item.cpp.

6014{
6015 return type->count_by_charges();
6016}

References itype::count_by_charges(), and type.

Referenced by activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), item_stack::amount_can_fit(), base_volume(), basic_info(), burn(), Character::can_eat(), repair_item_actor::can_repair_target(), charges_of_internal(), charges_per_volume(), craft_command::check_item_components_missing(), complete_craft(), crafting::complete_disassemble(), player::consume_items(), count(), craft_has_charges(), recipe::create_byproducts(), recipe::create_results(), display_name(), display_stacked_with(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), mattack::eat_food(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), iuse_transform::finalize(), emit_actor::finalize(), for_each_item_in_both(), Character::get_acquirable_energy(), recipe::get_consistency_error(), requirement_data::get_folded_list(), iexamine::get_harvest_items(), monexamine::give_items_to(), repair_item_actor::handle_components(), item_comp::has(), talk_function::individual_mission(), io(), repair_inventory_preset::is_shown(), merge_charges(), to_cbc_migration::migration_required(), mod_charges(), mod_damage(), Item_modifier::modify(), advanced_inventory::move_all_items(), move_item(), npc_throw(), pickup::obtain_and_tokenize_items(), pick_one_up(), pickup::pick_up(), activity_handlers::plant_seed_finish(), price(), advanced_inventory::query_charges(), vehicle::reload_seeds(), player::select_item_component(), talk_effect_fun_t::set_u_buy_item(), talk_effect_fun_t::set_u_sell_item(), simulate_burn(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::throw_range(), ranged::throwing_dispersion(), npc_trading::trade(), try_consume(), units_remaining(), units_sufficient(), inventory::update_quality_cache(), use_charges(), volume(), weight(), Character::weight_carried_reduced_by(), and debug_menu::wishitem().

◆ count_by_charges() [2/2]

bool item::count_by_charges ( const itype_id id)
static

Whether the item is counted by charges, this is a static wrapper around count_by_charges, that does not need an items instance.

Definition at line 9948 of file item.cpp.

9949{
9950 return id->count_by_charges();
9951}

◆ covers() [1/2]

◆ covers() [2/2]

bool item::covers ( const bodypart_id bp) const

Definition at line 751 of file item.cpp.

752{
753 return get_covered_body_parts().test( bp->token );
754}
bool test(const body_part &bp) const
Definition: bodypart.h:250

References get_covered_body_parts(), and body_part_set::test().

◆ craft_has_charges()

bool item::craft_has_charges ( )

Definition at line 6023 of file item.cpp.

6024{
6025 if( count_by_charges() ) {
6026 return true;
6027 } else if( ammo_types().empty() ) {
6028 return true;
6029 }
6030
6031 return false;
6032}

References ammo_types(), and count_by_charges().

Referenced by crafting::complete_disassemble(), and recipe::create_byproducts().

◆ cut_resist()

int item::cut_resist ( bool  to_self = false) const

Definition at line 6067 of file item.cpp.

6068{
6069 if( is_null() ) {
6070 return 0;
6071 }
6072
6073 const int base_thickness = get_thickness();
6074 float resist = 0;
6076 int eff_thickness = 1;
6077
6078 // base resistance
6079 // Don't give reinforced items +armor, just more resistance to ripping
6080 const int dmg = damage_level( 4 );
6081 const int eff_damage = to_self ? std::min( dmg, 0 ) : std::max( dmg, 0 );
6082 eff_thickness = std::max( 1, base_thickness - eff_damage );
6083
6084 const std::vector<const material_type *> mat_types = made_of_types();
6085 if( !mat_types.empty() ) {
6086 for( const material_type *mat : mat_types ) {
6087 resist += mat->cut_resist();
6088 }
6089 // Average based on number of materials.
6090 resist /= mat_types.size();
6091 }
6092
6093 return std::lround( ( resist * eff_thickness ) + mod );
6094}
@ clothing_mod_type_cut
Definition: clothing_mod.h:20

References clothing_mod_type_cut, damage_level(), get_clothing_mod_val(), get_thickness(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), stab_resist(), and sew_advanced_actor::use().

◆ damage()

◆ damage_color()

nc_color item::damage_color ( ) const

Provide color for UI display dependent upon current item damage level.

Definition at line 6271 of file item.cpp.

6272{
6273 // TODO: unify with veh_interact::countDurability
6274 switch( damage_level( 4 ) ) {
6275 default:
6276 // reinforced
6277 if( damage() <= min_damage() ) {
6278 // fully reinforced
6279 return c_green;
6280 } else {
6281 return c_light_green;
6282 }
6283 case 0:
6284 return c_light_green;
6285 case 1:
6286 return c_yellow;
6287 case 2:
6288 return c_magenta;
6289 case 3:
6290 return c_light_red;
6291 case 4:
6292 if( damage() >= max_damage() ) {
6293 return c_dark_gray;
6294 } else {
6295 return c_red;
6296 }
6297 }
6298}
int min_damage() const
Minimum amount of damage to an item (state of maximum repair)
Definition: item.cpp:6219

References c_dark_gray, c_green, c_light_green, c_light_red, c_magenta, c_red, c_yellow, damage(), damage_level(), max_damage(), and min_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ damage_level()

int item::damage_level ( int  max) const

Scale item damage to the given number of levels.

This function is here mostly for back-compatibility. It should not be used when doing continuous math with the damage value: use damage() instead.

For example, for max = 4, min_damage = -1000, max_damage = 4000 damage level -1000 ~ -1 -1 0 0 1 ~ 1333 1 1334 ~ 2666 2 2667 ~ 3999 3 4000 4

Parameters
maxMaximum number of levels

Definition at line 704 of file item.cpp.

705{
706 if( damage_ == 0 || max <= 0 ) {
707 return 0;
708 } else if( max_damage() <= 1 ) {
709 return damage_ > 0 ? max : damage_;
710 } else if( damage_ < 0 ) {
711 return -( ( max - 1 ) * ( -damage_ - 1 ) / ( max_damage() - 1 ) + 1 );
712 } else {
713 return ( max - 1 ) * ( damage_ - 1 ) / ( max_damage() - 1 ) + 1;
714 }
715}

References damage_, and max_damage().

Referenced by Character::armor_absorb(), bash_resist(), bullet_resist(), activity_handlers::butcher_finish(), butchery_drops_harvest(), iuse::chainsaw_off(), crafting::complete_disassemble(), iuse::cs_lajatang_off(), cut_resist(), salvage_actor::cut_up(), damage_color(), vehicle_part::damage_level(), damage_melee(), damage_symbol(), veh_interact::do_repair(), durability_indicator(), gun_damage(), gun_dispersion(), avatar_funcs::gunmod_installation_odds(), monster::init_from_item(), vehicle_part::properties_to_item(), ready_to_revive(), repair_item_actor::repair_chance(), game::save_cyborg(), iuse::trimmer_off(), and fireweapon_off_actor::use().

◆ damage_melee()

int item::damage_melee ( damage_type  dt) const

Damage of given type caused when this item is used as melee weapon.

Definition at line 5196 of file item.cpp.

5197{
5198 assert( dt >= DT_NULL && dt < NUM_DT );
5199 if( is_null() ) {
5200 return 0;
5201 }
5202
5203 // effectiveness is reduced by 10% per damage level
5204 int res = type->melee[ dt ];
5205 res -= res * std::max( damage_level( 4 ), 0 ) * 0.1;
5206
5207 // apply type specific flags
5208 switch( dt ) {
5209 case DT_BASH:
5211 res *= 0.5;
5212 }
5213 break;
5214
5215 case DT_CUT:
5216 case DT_STAB:
5217 if( has_flag( flag_DIAMOND ) ) {
5218 res *= 1.3;
5219 }
5220 break;
5221
5222 default:
5223 break;
5224 }
5225
5226 // consider any melee gunmods
5227 if( is_gun() ) {
5228 const std::vector<const item *> &mods = gunmods();
5229 return std::accumulate( mods.begin(), mods.end(), res, [dt]( int last_max, const item * it ) {
5230 return it->has_flag( flag_MELEE_GUNMOD ) ? std::max( last_max, it->damage_melee( dt ) ) : last_max;
5231 } );
5232
5233 }
5234
5235 switch( dt ) {
5236 case DT_BASH:
5238 break;
5239 case DT_CUT:
5241 break;
5242 case DT_STAB:
5244 break;
5245 default:
5246 break;
5247 }
5248
5249 return std::max( res, 0 );
5250}
static const std::string flag_DIAMOND("DIAMOND")
static const std::string flag_REDUCED_BASHING("REDUCED_BASHING")
std::array< int, NUM_DT > melee
Damage output in melee for zero or more damage types.
Definition: itype.h:994

References bonus_from_enchantments_wielded(), damage_level(), DT_BASH, DT_CUT, DT_NULL, DT_STAB, flag_DIAMOND(), flag_REDUCED_BASHING(), gunmods(), has_flag(), is_gun(), is_null(), enchant_vals::ITEM_DAMAGE_BASH, enchant_vals::ITEM_DAMAGE_CUT, enchant_vals::ITEM_DAMAGE_STAB, itype::melee, NUM_DT, and type.

Referenced by base_damage_melee(), combat_info(), weapon_inventory_preset::deals_melee_damage(), character_effects::intimidation(), is_melee(), ma_requirements::is_valid_weapon(), melee_skill(), Character::melee_special_effects(), melee_train(), Character::power_rating(), activity_handlers::pulp_do_turn(), Character::reach_attack(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), smash(), and npc::smash_ability().

◆ damage_resist()

int item::damage_resist ( damage_type  dt,
bool  to_self = false 
) const

Resistance provided by this item against damage type given by an enum.

Definition at line 6379 of file item.cpp.

6380{
6381 switch( dt ) {
6382 case DT_NULL:
6383 case NUM_DT:
6384 return 0;
6385 case DT_TRUE:
6386 case DT_BIOLOGICAL:
6387 case DT_ELECTRIC:
6388 case DT_COLD:
6389 // Currently hardcoded:
6390 // Items can never be damaged by those types
6391 // But they provide 0 protection from them
6392 return to_self ? INT_MAX : 0;
6393 case DT_BASH:
6394 return bash_resist( to_self );
6395 case DT_CUT:
6396 return cut_resist( to_self );
6397 case DT_ACID:
6398 return acid_resist( to_self );
6399 case DT_STAB:
6400 return stab_resist( to_self );
6401 case DT_HEAT:
6402 return fire_resist( to_self );
6403 case DT_BULLET:
6404 return bullet_resist( to_self );
6405 default:
6406 debugmsg( "Invalid damage type: %d", dt );
6407 }
6408
6409 return 0;
6410}
int stab_resist(bool to_self=false) const
Definition: item.cpp:6100
@ DT_COLD
Definition: damage.h:29
@ DT_ELECTRIC
Definition: damage.h:30
@ DT_TRUE
Definition: damage.h:22
@ DT_ACID
Definition: damage.h:26
@ DT_BULLET
Definition: damage.h:31
@ DT_BIOLOGICAL
Definition: damage.h:23
@ DT_HEAT
Definition: damage.h:28

References acid_resist(), bash_resist(), bullet_resist(), cut_resist(), debugmsg, DT_ACID, DT_BASH, DT_BIOLOGICAL, DT_BULLET, DT_COLD, DT_CUT, DT_ELECTRIC, DT_HEAT, DT_NULL, DT_STAB, DT_TRUE, fire_resist(), NUM_DT, and stab_resist().

Referenced by Character::armor_absorb(), and resistances::resistances().

◆ damage_symbol()

std::string item::damage_symbol ( ) const

Provide prefix symbol for UI display dependent upon current item damage level.

Definition at line 6300 of file item.cpp.

6301{
6302 switch( damage_level( 4 ) ) {
6303 default:
6304 // reinforced
6305 return _( R"(++)" );
6306 case 0:
6307 return _( R"(||)" );
6308 case 1:
6309 return _( R"(|\)" );
6310 case 2:
6311 return _( R"(|.)" );
6312 case 3:
6313 return _( R"(\.)" );
6314 case 4:
6315 if( damage() >= max_damage() ) {
6316 return _( R"(XX)" );
6317 } else {
6318 return _( R"(..)" );
6319 }
6320
6321 }
6322}

References _, damage(), damage_level(), and max_damage().

Referenced by durability_indicator(), vehicle_part::name(), and veh_utils::repair_part().

◆ deactivate()

item & item::deactivate ( const Character ch = nullptr,
bool  alert = true 
)

Filter converting this instance to the inactive type If the item is either inactive or cannot be deactivated is a no-op.

Parameters
chcharacter currently possessing or acting upon the item (if any)
alertwhether to display any messages
Returns
same instance to allow method chaining

Definition at line 543 of file item.cpp.

544{
545 if( !active ) {
546 return *this; // no-op
547 }
548
549 if( is_tool() && type->tool->revert_to ) {
550 if( ch && alert && !type->tool->revert_msg.empty() ) {
551 ch->add_msg_if_player( m_info, _( type->tool->revert_msg ), tname() );
552 }
553 convert( *type->tool->revert_to );
554 active = false;
555
556 }
557 return *this;
558}
virtual void add_msg_if_player(const std::string &) const
Definition: creature.h:605
item & convert(const itype_id &new_type)
Filter converting this instance to another type preserving all other aspects.
Definition: item.cpp:536
@ m_info
Definition: enums.h:265

References _, active, Creature::add_msg_if_player(), alert, convert(), is_tool(), m_info, tname(), itype::tool, and type.

Referenced by iuse::note_bionics(), process_tool(), and fireweapon_on_actor::use().

◆ deserialize()

void item::deserialize ( JsonIn jsin)

Definition at line 2367 of file savegame_json.cpp.

2368{
2369 const JsonObject data = jsin.get_object();
2370 data.allow_omitted_members();
2371 io::JsonObjectInputArchive archive( data );
2372 io( archive );
2373 // made for fast forwarding time from 0.D to 0.E
2374 if( savegame_loading_version < 27 ) {
2376 }
2377 if( data.has_array( "contents" ) ) {
2378 std::list<item> items;
2379 data.read( "contents", items );
2380 contents = item_contents( items );
2381 } else {
2382 data.read( "contents", contents );
2383 }
2384
2385 // Sealed item migration: items with "unseals_into" set should always have contents
2387 convert( type->container->unseals_into );
2388 }
2389}
JsonObject get_object()
Definition: json.cpp:1432
bool has_array(const std::string &name) const
Definition: json.cpp:483
void allow_omitted_members() const
Definition: json.cpp:151
bool read(const std::string &name, T &t, bool throw_on_error=true) const
Definition: json.h:941
Input archive reading data from a Json object.
Definition: cata_io.h:185
void io(Archive &)
bool is_non_resealable_container() const
Whether removing this item's contents will permanently alter it.
Definition: item.cpp:6737
void legacy_fast_forward_time()
Definition: item.cpp:10036
int savegame_loading_version
Definition: savegame.cpp:64

References JsonObject::allow_omitted_members(), itype::container, contents, convert(), item_contents::empty(), JsonIn::get_object(), JsonObject::has_array(), io(), is_non_resealable_container(), legacy_fast_forward_time(), JsonObject::read(), savegame_loading_version, and type.

Referenced by item::craft_data::deserialize(), inventory::json_load_items(), monster::load(), and release_monster().

◆ destroyed_at_zero_charges()

bool item::destroyed_at_zero_charges ( ) const

Definition at line 6520 of file item.cpp.

6521{
6522 return ( is_ammo() || is_food() );
6523}

References is_ammo(), and is_food().

◆ detonate()

bool item::detonate ( const tripoint p,
std::vector< item > &  drops 
)

Detonates the item and adds remains (if any) to drops.

Returns true if the item actually detonated, potentially destroying other items and invalidating iterators. Should NOT be called on an item on the map, but on a local copy.

Definition at line 8762 of file item.cpp.

8763{
8764 if( type->explosion ) {
8766 return true;
8767 } else if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8768 int charges_remaining = charges;
8769 const int rounds_exploded = rng( 1, charges_remaining );
8770 // Yank the exploding item off the map for the duration of the explosion
8771 // so it doesn't blow itself up.
8772 const islot_ammo &ammo_type = *type->ammo;
8773
8774 if( ammo_type.special_cookoff ) {
8775 // If it has a special effect just trigger it.
8776 apply_ammo_effects( p, ammo_type.ammo_effects, activated_by.get() );
8777 }
8778 charges_remaining -= rounds_exploded;
8779 if( charges_remaining > 0 ) {
8780 item temp_item = *this;
8781 temp_item.charges = charges_remaining;
8782 drops.push_back( temp_item );
8783 }
8784
8785 return true;
8786 } else if( !contents.empty() && ( !type->magazine || !type->magazine->protects_contents ) ) {
8787 std::vector<item *> removed_items;
8788 bool detonated = false;
8789 for( item *it : contents.all_items_top() ) {
8790 if( it->detonate( p, drops ) ) {
8791 removed_items.push_back( it );
8792 detonated = true;
8793 }
8794 }
8795 for( item *it : removed_items ) {
8796 remove_item( *it );
8797 }
8798 return detonated;
8799 }
8800
8801 return false;
8802}
safe_reference< Character > activated_by
Definition: item.h:2242
void explosion(const tripoint &p, Creature *source, float power, float factor, bool fire, int legacy_casing_mass, float)
Legacy explosion function.
Definition: explosion.cpp:1079
void apply_ammo_effects(const tripoint &p, const std::set< ammo_effect_str_id > &effects, Creature *source)
Definition: projectile.cpp:110
explosion_data explosion
Definition: itype.h:945

References activated_by, item_contents::all_items_top(), itype::ammo, ammo_type(), apply_ammo_effects(), charges, contents, item_contents::empty(), explosion_handler::explosion(), itype::explosion, itype::magazine, visitable< item >::remove_item(), rng(), and type.

Referenced by map::process_fields_in_submap(), and map::smash_items().

◆ disassembly_info()

void item::disassembly_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3177 of file item.cpp.

3179{
3181 return;
3182 }
3184 return;
3185 }
3186
3188 const requirement_data &req = dis.disassembly_requirements();
3189 if( !req.is_empty() ) {
3190 const std::string approx_time = to_string_approx( time_duration::from_turns( dis.time / 100 ) );
3191
3193 const std::string comps_str = enumerate_as_string( comps_list.begin(), comps_list.end(),
3194 []( const std::vector<item_comp> &comp_opts ) {
3195 return comp_opts.front().to_string();
3196 } );
3197
3198 std::vector<std::string> reqs_list;
3199 const requirement_data::alter_tool_comp_vector &tools_list = req.get_tools();
3200 for( const std::vector<tool_comp> &it : tools_list ) {
3201 if( !it.empty() ) {
3202 reqs_list.push_back( it.front().to_string() );
3203 }
3204 }
3206 for( const std::vector<quality_requirement> &it : quals_list ) {
3207 if( !it.empty() ) {
3208 reqs_list.push_back( it.front().to_colored_string() );
3209 }
3210 }
3211
3212 std::string descr;
3213 if( reqs_list.empty() ) {
3214 //~ 1 is approx. time (e.g. 'about 5 minutes'), 2 is a list of items
3215 descr = string_format( _( "<bold>Disassembly</bold> takes %1$s and might yield: %2$s." ),
3216 approx_time, comps_str );
3217 } else {
3218 const std::string reqs_str = enumerate_as_string( reqs_list );
3219 descr = string_format(
3220 //~ 1 is approx. time, 2 is a list of items and tools with qualities, 3 is a list of items.
3221 //~ Bold text in the middle makes it easier to see where the second list starts.
3222 _( "<bold>Disassembly</bold> takes %1$s, requires %2$s and <bold>might yield</bold>: %3$s." ),
3223 approx_time, reqs_str, comps_str );
3224 }
3225
3227 info.push_back( iteminfo( "DESCRIPTION", descr ) );
3228 }
3229}
std::string to_string_approx(const time_duration &dur, const bool verbose)
Returns approximate duration.
Definition: calendar.cpp:361
static const recipe & get_uncraft(const itype_id &id)
Returns disassembly recipe (or null recipe if no match)
Definition: recipe.h:35
requirement_data disassembly_requirements() const
If recipe can be used for disassembly fetch the combined requirements.
Definition: recipe.h:96
int time
Definition: recipe.h:61
static constexpr time_duration from_turns(const T t)
Named constructors to get a duration representing a multiple of the named time units.
Definition: calendar.h:204
@ DESCRIPTION_COMPONENTS_DISASSEMBLE
The *_vector members represent list of alternatives requirements: alter_tool_comp_vector = { * { { a,...
Definition: requirements.h:215
const alter_tool_comp_vector & get_tools() const
const alter_item_comp_vector & get_components() const
std::vector< std::vector< quality_requirement > > alter_quali_req_vector
Definition: requirements.h:222
bool is_empty() const
empty requirements are not necessary null
Definition: requirements.h:247
std::vector< std::vector< item_comp > > alter_item_comp_vector
Definition: requirements.h:223
const alter_quali_req_vector & get_qualities() const
std::vector< std::vector< tool_comp > > alter_tool_comp_vector
Definition: requirements.h:221

References _, components, DESCRIPTION_COMPONENTS_DISASSEMBLE, DESCRIPTION_COMPONENTS_MADEFROM, recipe::disassembly_requirements(), enumerate_as_string(), time_duration::from_turns(), requirement_data::get_components(), requirement_data::get_qualities(), requirement_data::get_tools(), recipe_dictionary::get_uncraft(), info(), insert_separation_line(), requirement_data::is_empty(), string_format(), iteminfo_query::test(), recipe::time, to_string_approx(), and typeId().

Referenced by info().

◆ display_money()

std::string item::display_money ( unsigned int  quantity,
unsigned int  total,
const std::optional< unsigned int > &  selected = std::nullopt 
) const

Definition at line 4807 of file item.cpp.

4809{
4810 if( selected ) {
4811 //~ This is a string to display the selected and total amount of money in a stack of cash cards.
4812 //~ %1$s is the display name of cash cards.
4813 //~ %2$s is the total amount of money.
4814 //~ %3$s is the selected amount of money.
4815 //~ Example: "cash cards $15.35 of $20.48"
4816 return string_format( pgettext( "cash card and money", "%1$s %3$s of %2$s" ), tname( quantity ),
4817 format_money( total ), format_money( *selected ) );
4818 } else {
4819 //~ This is a string to display the total amount of money in a stack of cash cards.
4820 //~ %1$s is the display name of cash cards.
4821 //~ %2$s is the total amount of money on the cash cards.
4822 //~ Example: "cash cards $20.48"
4823 return string_format( pgettext( "cash card and money", "%1$s %2$s" ), tname( quantity ),
4824 format_money( total ) );
4825 }
4826}
std::string format_money(int cents)
Definition: output.h:932
const char * pgettext(const char *context, const char *msgid)

References format_money(), pgettext(), string_format(), and tname().

Referenced by inventory_selector_preset::get_caption(), and selection_column_preset::get_caption().

◆ display_name()

std::string item::display_name ( unsigned int  quantity = 1) const

Returns the item name and the charges or contained charges (if the item can have charges at all).

Calls tname with given quantity and with_prefix being true.

Definition at line 4828 of file item.cpp.

4829{
4830 std::string name = tname( quantity );
4831 std::string sidetxt;
4832 std::string amt;
4833
4834 switch( get_side() ) {
4835 case side::BOTH:
4836 case side::num_sides:
4837 break;
4838 case side::LEFT:
4839 sidetxt = string_format( " (%s)", _( "left" ) );
4840 break;
4841 case side::RIGHT:
4842 sidetxt = string_format( " (%s)", _( "right" ) );
4843 break;
4844 }
4845 avatar &you = get_avatar();
4846 int amount = 0;
4847 int max_amount = 0;
4848 bool has_item = is_container() && contents.num_item_stacks() == 1;
4849 bool has_ammo = is_ammo_container() && contents.num_item_stacks() == 1;
4850 bool contains = has_item || has_ammo;
4851 bool show_amt = false;
4852 // We should handle infinite charges properly in all cases.
4853 if( contains ) {
4854 amount = contents.front().charges;
4856 } else if( is_book() && get_chapters() > 0 ) {
4857 // a book which has remaining unread chapters
4858 amount = get_remaining_chapters( you );
4859 } else if( ammo_capacity() > 0 ) {
4860 // anything that can be reloaded including tools, magazines, guns and auxiliary gunmods
4861 // but excluding bows etc., which have ammo, but can't be reloaded
4862 amount = ammo_remaining();
4863 max_amount = ammo_capacity();
4864 show_amt = !has_flag( flag_RELOAD_AND_SHOOT );
4865 } else if( count_by_charges() && !has_infinite_charges() ) {
4866 // A chargeable item
4867 amount = charges;
4868 max_amount = ammo_capacity();
4869 } else if( is_battery() ) {
4870 show_amt = true;
4871 amount = to_joule( energy_remaining() );
4872 max_amount = to_joule( type->battery->max_capacity );
4873 }
4874
4875 std::string ammotext;
4876 if( ( ( is_gun() && ammo_required() ) || is_magazine() ) && get_option<bool>( "AMMO_IN_NAMES" ) ) {
4877 if( !ammo_current().is_null() ) {
4878 ammotext = ammo_current()->nname( 1 );
4879 } else {
4880 ammotext = ammotype( *ammo_types().begin() )->name();
4881 }
4882 }
4883
4884 if( amount || show_amt ) {
4885 if( is_money() ) {
4886 amt = string_format( " $%.2f", amount / 100.0 );
4887 } else {
4888 if( !ammotext.empty() ) {
4889 ammotext = " " + ammotext;
4890 }
4891
4892 if( max_amount != 0 ) {
4893 amt = string_format( " (%i/%i%s)", amount, max_amount, ammotext );
4894 } else {
4895 amt = string_format( " (%i%s)", amount, ammotext );
4896 }
4897 }
4898 } else if( !ammotext.empty() ) {
4899 amt = " (" + ammotext + ")";
4900 }
4901
4902 // HACK: This is a hack to prevent possible crashing when displaying maps as items during character creation
4904 // TODO: fix point types
4905 tripoint map_pos_omt =
4906 get_var( "reveal_map_center_omt", you.global_omt_location().raw() );
4907 tripoint_abs_sm map_pos =
4908 project_to<coords::sm>( tripoint_abs_omt( map_pos_omt ) );
4909 const city *c = overmap_buffer.closest_city( map_pos ).city;
4910 if( c != nullptr ) {
4911 name = string_format( "%s %s", c->name, name );
4912 }
4913 }
4914
4915 return string_format( "%s%s%s", name, sidetxt, amt );
4916}
@ num_sides
tripoint_abs_omt global_omt_location() const
Returns the location of the player in global overmap terrain coordinates.
Definition: character.cpp:6272
constexpr Point & raw()
Definition: coordinates.h:111
bool is_ammo_container() const
Definition: item.cpp:6670
bool has_infinite_charges() const
Definition: item.cpp:9982
itype_id ammo_current() const
Specific ammo type, returns "null" if item is neither ammo nor loaded with any.
Definition: item.cpp:7572
bool is_map() const
Definition: item.cpp:6722
units::energy energy_remaining() const
Quantity of energy currently loaded in tool or battery.
Definition: item.cpp:7386
int charges_per_volume(const units::volume &vol) const
Number of (charges of) this item that fit into the given volume.
Definition: item.cpp:867
units::volume get_container_capacity() const
It returns the total capacity (volume) of the container for liquids.
Definition: item.cpp:8409
side get_side() const
Returns side item currently worn on.
Definition: item.cpp:811
int get_chapters() const
How many chapters the book has (if any).
Definition: item.cpp:7097
city_reference closest_city(const tripoint_abs_sm &center)
Find the closest city.
bool has_item(const item &it) const
Returns true if this visitable instance contains the item.
Definition: visitable.cpp:95
coords::coord_point< tripoint, coords::origin::abs, coords::omt > tripoint_abs_omt
Definition: coordinates.h:493
static const std::string flag_RELOAD_AND_SHOOT("RELOAD_AND_SHOOT")
const time_point turn_zero
Represents time point 0.
Definition: calendar.cpp:26
overmapbuffer overmap_buffer
const struct city * city
The city itself, points into overmap::cities.
Definition: overmapbuffer.h:81
Definition: overmap.h:55

References _, ammo_capacity(), ammo_current(), ammo_remaining(), ammo_required(), ammo_types(), itype::battery, BOTH, c, charges, charges_per_volume(), city_reference::city, overmapbuffer::closest_city(), contains, contents, count_by_charges(), energy_remaining(), flag_RELOAD_AND_SHOOT(), item_contents::front(), get_avatar(), get_chapters(), get_container_capacity(), get_remaining_chapters(), get_side(), get_var(), Character::global_omt_location(), has_flag(), has_infinite_charges(), visitable< item >::has_item(), is_ammo_container(), is_battery(), is_book(), is_container(), is_gun(), is_magazine(), is_map(), is_money(), is_null(), LEFT, ammunition_type::name(), om_direction::name(), itype::nname(), item_contents::num_item_stacks(), num_sides, overmap_buffer, coords::coord_point< Point, Origin, Scale >::raw(), RIGHT, string_format(), tname(), units::to_joule(), calendar::turn, calendar::turn_zero, and type.

Referenced by act_vehicle_unload_fuel(), monexamine::add_armor(), monexamine::attach_bag_to(), veh_interact::can_remove_part(), game_menus::inv::container_for(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), liquid_handler::get_liquid_target(), game::handle_action(), handle_problematic_pickup(), pickup::handle_spillable_contents(), inscribe_actor::item_inscription(), game::list_items(), pick_one_up(), pickup::pick_up(), trading_window::update_win(), and musical_instrument_actor::use().

◆ display_stacked_with()

bool item::display_stacked_with ( const item rhs,
bool  check_components = false 
) const

Whether two items should stack when displayed in a inventory menu.

This is different from stacks_with, when two previously non-stackable items are now stackable and mergeable because, for example, they reaches the same temperature. This is necessary to avoid misleading stacks like "3 items-count-by-charge (5)".

Definition at line 887 of file item.cpp.

888{
889 return !count_by_charges() && stacks_with( rhs, check_components );
890}
bool stacks_with(const item &rhs, bool check_components=false, bool skip_type_check=false) const
Definition: item.cpp:892

References count_by_charges(), and stacks_with().

Referenced by pickup::stack_for_pickup_ui().

◆ dps() [1/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc 
) const

Definition at line 1446 of file item.cpp.

1447{
1448 return dps( for_display, for_calc, get_avatar() );
1449}

References dps(), and get_avatar().

◆ dps() [2/2]

std::map< std::string, double > item::dps ( bool  for_display,
bool  for_calc,
const player guy 
) const

calculate effective dps against a stock set of monsters.

by default, assume g->u is wielding for_display - include monsters intended for display purposes for_calc - include monsters intended for evaluation purposes for_display and for_calc are inclusive

Definition at line 1431 of file item.cpp.

1433{
1434 std::map<std::string, double> results;
1435 for( const std::pair<translation, dps_comp_data> &comp_mon : dps_comp_monsters ) {
1436 if( ( comp_mon.second.display != for_display ) &&
1437 ( comp_mon.second.evaluate != for_calc ) ) {
1438 continue;
1439 }
1440 monster test_mon = monster( comp_mon.second.mon_id );
1441 results[ comp_mon.first.translated() ] = effective_dps( guy, test_mon );
1442 }
1443 return results;
1444}
double effective_dps(const player &guy, const monster &mon) const
Calculate the item's effective damage per second past armor when wielded by a character against a mon...
Definition: item.cpp:1328
static const std::vector< std::pair< translation, dps_comp_data > > dps_comp_monsters
Definition: item.cpp:1424

References dps_comp_monsters, and effective_dps().

Referenced by average_dps(), combat_info(), dps(), and ideal_ranged_dps().

◆ durability_indicator()

std::string item::durability_indicator ( bool  include_intact = false) const

Provides a prefix for the durability state of the item.

with ITEM_HEALTH_BAR enabled, returns a symbol with color tag already applied. Otherwise, returns an adjective. if include_intact is true, this provides a string for the corner case of a player with ITEM_HEALTH_BAR disabled, but we need still a string for some reason.

Definition at line 6324 of file item.cpp.

6325{
6326 std::string outputstring;
6327
6328 if( damage() < 0 ) {
6329 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6330 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6331 } else if( is_gun() ) {
6332 outputstring = pgettext( "damage adjective", "accurized " );
6333 } else {
6334 outputstring = pgettext( "damage adjective", "reinforced " );
6335 }
6336 } else if( has_flag( flag_CORPSE ) ) {
6337 if( damage() > 0 ) {
6338 switch( damage_level( 4 ) ) {
6339 case 1:
6340 outputstring = pgettext( "damage adjective", "bruised " );
6341 break;
6342 case 2:
6343 outputstring = pgettext( "damage adjective", "damaged " );
6344 break;
6345 case 3:
6346 outputstring = pgettext( "damage adjective", "mangled " );
6347 break;
6348 default:
6349 outputstring = pgettext( "damage adjective", "pulped " );
6350 break;
6351 }
6352 }
6353 } else if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
6354 outputstring = colorize( damage_symbol() + "\u00A0", damage_color() );
6355 } else {
6356 outputstring = string_format( "%s ", get_base_material().dmg_adj( damage_level( 4 ) ) );
6357 if( include_intact && outputstring == " " ) {
6358 outputstring = _( "fully intact " );
6359 }
6360 }
6361
6362 return outputstring;
6363}
std::string damage_symbol() const
Provide prefix symbol for UI display dependent upon current item damage level.
Definition: item.cpp:6300
const material_type & get_base_material() const
Get the basic (main) material of this item.
Definition: item.cpp:7159
nc_color damage_color() const
Provide color for UI display dependent upon current item damage level.
Definition: item.cpp:6271

References _, colorize(), damage(), damage_color(), damage_level(), damage_symbol(), flag_CORPSE(), get_base_material(), has_flag(), is_gun(), pgettext(), and string_format().

Referenced by colorized_item_name(), damage_item(), iuse::gun_repair(), repair_item_actor::repair(), and tname().

◆ effective_dps()

double item::effective_dps ( const player guy,
const monster mon 
) const

Calculate the item's effective damage per second past armor when wielded by a character against a monster.

Definition at line 1328 of file item.cpp.

1329{
1330 const float mon_dodge = mon.get_dodge();
1331 float base_hit = guy.get_dex() / 4.0f + guy.get_hit_weapon( *this );
1332 base_hit *= std::max( 0.25f, 1.0f - guy.encumb( bp_torso ) / 100.0f );
1333 float mon_defense = mon_dodge + mon.size_melee_penalty() / 5.0;
1334 constexpr double hit_trials = 10000.0;
1335 const int rng_mean = std::max( std::min( static_cast<int>( base_hit - mon_defense ), 20 ),
1336 -20 ) + 20;
1337 double num_all_hits = hits_by_accuracy[ rng_mean ];
1338 /* critical hits have two chances to occur: triple critical hits happen much less frequently,
1339 * and double critical hits can only occur if a hit roll is more than 1.5 * monster dodge.
1340 * Not the hit roll used to determine the attack, another one.
1341 * the way the math works, some percentage of the total hits are eligible to be double
1342 * critical hits, and the rest are eligible to be triple critical hits, but in each case,
1343 * only some small percent of them actually become critical hits.
1344 */
1345 const int rng_high_mean = std::max( std::min( static_cast<int>( base_hit - 1.5 * mon_dodge ),
1346 20 ), -20 ) + 20;
1347 double num_high_hits = hits_by_accuracy[ rng_high_mean ] * num_all_hits / hit_trials;
1348 double double_crit_chance = guy.crit_chance( 4, 0, *this );
1349 double crit_chance = guy.crit_chance( 0, 0, *this );
1350 double num_low_hits = std::max( 0.0, num_all_hits - num_high_hits );
1351
1352 double moves_per_attack = guy.attack_cost( *this );
1353 // attacks that miss do no damage but take time
1354 double total_moves = ( hit_trials - num_all_hits ) * moves_per_attack;
1355 double total_damage = 0.0;
1356 double num_crits = std::min( num_low_hits * crit_chance + num_high_hits * double_crit_chance,
1357 num_all_hits );
1358 // critical hits are counted separately
1359 double num_hits = num_all_hits - num_crits;
1360 // sum average damage past armor and return the number of moves required to achieve
1361 // that damage
1362 const auto calc_effective_damage = [ &, moves_per_attack]( const double num_strikes,
1363 const bool crit, const player & guy, const monster & mon ) {
1364 monster temp_mon = mon;
1365 double subtotal_damage = 0;
1366 damage_instance base_damage;
1367 guy.roll_all_damage( crit, base_damage, true, *this );
1368 damage_instance dealt_damage = base_damage;
1369 temp_mon.absorb_hit( bodypart_id( "torso" ), dealt_damage );
1370 dealt_damage_instance dealt_dams;
1371 for( const damage_unit &dmg_unit : dealt_damage.damage_units ) {
1372 int cur_damage = 0;
1373 int total_pain = 0;
1374 temp_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1375 if( cur_damage > 0 ) {
1376 dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1377 }
1378 }
1379 double damage_per_hit = dealt_dams.total_damage();
1380 subtotal_damage = damage_per_hit * num_strikes;
1381 double subtotal_moves = moves_per_attack * num_strikes;
1382
1383 if( has_technique( rapid_strike ) ) {
1384 monster temp_rs_mon = mon;
1385 damage_instance rs_base_damage;
1386 guy.roll_all_damage( crit, rs_base_damage, true, *this );
1387 damage_instance dealt_rs_damage = rs_base_damage;
1388 for( damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1389 dmg_unit.damage_multiplier *= 0.66;
1390 }
1391 temp_rs_mon.absorb_hit( bodypart_id( "torso" ), dealt_rs_damage );
1392 dealt_damage_instance rs_dealt_dams;
1393 for( const damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
1394 int cur_damage = 0;
1395 int total_pain = 0;
1396 temp_rs_mon.deal_damage_handle_type( dmg_unit, bodypart_id( "torso" ), cur_damage, total_pain );
1397 if( cur_damage > 0 ) {
1398 rs_dealt_dams.dealt_dams[ dmg_unit.type ] += cur_damage;
1399 }
1400 }
1401 double rs_damage_per_hit = rs_dealt_dams.total_damage();
1402 subtotal_moves *= 0.5;
1403 subtotal_damage *= 0.5;
1404 subtotal_moves += moves_per_attack * num_strikes * 0.33;
1405 subtotal_damage += rs_damage_per_hit * num_strikes * 0.5;
1406 }
1407 return std::make_pair( subtotal_moves, subtotal_damage );
1408 };
1409 std::pair<double, double> crit_summary = calc_effective_damage( num_crits, true, guy, mon );
1410 total_moves += crit_summary.first;
1411 total_damage += crit_summary.second;
1412 std::pair<double, double> summary = calc_effective_damage( num_hits, false, guy, mon );
1413 total_moves += summary.first;
1414 total_damage += summary.second;
1415 return total_damage * to_moves<double>( 1_seconds ) / total_moves;
1416}
int_id< body_part_type > bodypart_id
Definition: bodypart.h:24
virtual int get_dex() const
Definition: character.cpp:4096
float get_hit_weapon(const item &weap) const
Gets melee accuracy component from weapon+skills.
Definition: melee.cpp:334
int encumb(body_part bp) const
Returns ENC provided by armor, etc.
Definition: character.cpp:4029
int size_melee_penalty() const
Definition: creature.cpp:483
bool has_technique(const matec_id &tech) const
Whether the item supports a specific martial art technique (either through its type,...
Definition: item.cpp:5447
void deal_damage_handle_type(const damage_unit &du, bodypart_id bp, int &damage, int &pain) override
Definition: monster.cpp:1621
float get_dodge() const override
Definition: monster.cpp:2002
void absorb_hit(const bodypart_id &bp, damage_instance &dam) override
Definition: monster.cpp:1404
Definition: player.h:84
static const double hits_by_accuracy[41]
Definition: item.cpp:1316
static const matec_id rapid_strike("RAPID")
damage_type type
Definition: damage.h:36
float damage_multiplier
Definition: damage.h:40
std::array< int, NUM_DT > dealt_dams
Definition: damage.h:86
int total_damage() const
Definition: damage.cpp:180

References monster::absorb_hit(), Character::attack_cost(), bp_torso, Character::crit_chance(), damage_unit::damage_multiplier, damage_instance::damage_units, monster::deal_damage_handle_type(), dealt_damage_instance::dealt_dams, Character::encumb(), Character::get_dex(), monster::get_dodge(), Character::get_hit_weapon(), has_technique(), hits_by_accuracy, rapid_strike, Character::roll_all_damage(), Creature::size_melee_penalty(), dealt_damage_instance::total_damage(), and damage_unit::type.

Referenced by dps().

◆ energy_remaining()

units::energy item::energy_remaining ( ) const

Quantity of energy currently loaded in tool or battery.

Definition at line 7386 of file item.cpp.

7387{
7388 if( is_battery() ) {
7389 return energy;
7390 }
7391
7392 return 0_J;
7393}
units::energy energy
Definition: item.h:2204

References energy, and is_battery().

Referenced by display_name(), mod_energy(), process_vehicle_items(), and charger_tile::update_internal().

◆ engine_displacement()

int item::engine_displacement ( ) const

for combustion engines the displacement (cc)

Definition at line 4120 of file item.cpp.

4121{
4122 return type->engine ? type->engine->displacement : 0;
4123}
cata::value_ptr< islot_engine > engine
Definition: itype.h:856

References itype::engine, and type.

Referenced by veh_interact::display_details(), vehicle_part::name(), vehicle::part_vpower_w(), and tname().

◆ erase_var()

void item::erase_var ( const std::string &  name)

◆ faults_potential()

std::set< fault_id > item::faults_potential ( ) const

What faults can potentially occur with this item?

Definition at line 6812 of file item.cpp.

6813{
6814 std::set<fault_id> res;
6815 res.insert( type->faults.begin(), type->faults.end() );
6816 return res;
6817}
std::set< fault_id > faults
What faults (if any) can occur.
Definition: itype.h:1017

References itype::faults, and type.

Referenced by vehicle_part::faults_potential(), ranged::handle_gun_damage(), and examine_item_menu::rate_action_mend().

◆ fill_with()

void item::fill_with ( item liquid,
int  amount = INFINITE_CHARGES 
)

Fill item with liquid up to its capacity.

This works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to fill the container with.
amountAmount to fill item with, capped by remaining capacity

Definition at line 8576 of file item.cpp.

8577{
8578 amount = std::min( get_remaining_capacity_for_liquid( liquid, true ),
8579 std::min( amount, liquid.charges ) );
8580 if( amount <= 0 ) {
8581 return;
8582 }
8583
8584 if( !is_container() ) {
8585 if( !is_reloadable_with( liquid.typeId() ) ) {
8586 debugmsg( "Tried to fill %s which is not a container and can't be reloaded with %s.",
8587 tname(), liquid.tname() );
8588 return;
8589 }
8590 ammo_set( liquid.typeId(), ammo_remaining() + amount );
8591 } else if( is_food_container() ) {
8592 item &cts = contents.front();
8593 // Use maximum rot between the two
8594 cts.set_relative_rot( std::max( cts.get_relative_rot(),
8595 liquid.get_relative_rot() ) );
8596 cts.mod_charges( amount );
8597 } else if( !is_container_empty() ) {
8598 // if container already has liquid we need to set the amount
8599 item &cts = contents.front();
8600 cts.mod_charges( amount );
8601 } else {
8602 item liquid_copy( liquid );
8603 liquid_copy.charges = amount;
8604 put_in( liquid_copy );
8605 }
8606
8607 liquid.mod_charges( -amount );
8609}
bool is_reloadable_with(const itype_id &ammo) const
Returns true if this item can be reloaded with specified ammo type at this moment.
Definition: item.cpp:6879
void mod_charges(int mod)
Modify the charges of this item, only use for items counted by charges! The item must have enough cha...
Definition: item.cpp:9742
void on_contents_changed()
Callback when contents of the item are affected in any way other than just processing.
Definition: item.cpp:4541
int get_remaining_capacity_for_liquid(const item &liquid, bool allow_bucket=false, std::string *err=nullptr) const
How much more of this liquid (in charges) can be put in this container.
Definition: item.cpp:8438

References ammo_remaining(), ammo_set(), charges, contents, debugmsg, item_contents::front(), get_relative_rot(), get_remaining_capacity_for_liquid(), is_container(), is_container_empty(), is_food_container(), is_reloadable_with(), mod_charges(), on_contents_changed(), put_in(), set_relative_rot(), tname(), and typeId().

Referenced by veh_interact::complete_vehicle(), vehicle_part::fill_with(), advanced_inventory::move_content(), Character::pour_into(), and reload().

◆ final_info()

void item::final_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3629 of file item.cpp.

3631{
3632 if( is_null() ) {
3633 return;
3634 }
3635
3636 // TODO: Remove
3637 const iteminfo_query *parts = &parts_ref;
3638
3639 const std::string space = " ";
3640
3642
3643 if( parts->test( iteminfo_parts::BASE_RIGIDITY ) ) {
3644 if( !type->rigid ) {
3645 info.emplace_back( "BASE",
3646 _( "* This item is <info>not rigid</info>. Its"
3647 " volume and encumbrance increase with contents." ) );
3648 }
3649 }
3650
3652 if( !conductive() ) {
3653 info.push_back( iteminfo( "BASE", _( "* This item <good>does not "
3654 "conduct</good> electricity." ) ) );
3655 } else if( has_flag( flag_CONDUCTIVE ) ) {
3656 info.push_back( iteminfo( "BASE",
3657 _( "* This item effectively <bad>conducts</bad> "
3658 "electricity, as it has no guard." ) ) );
3659 } else {
3660 info.push_back( iteminfo( "BASE", _( "* This item <bad>conducts</bad> electricity." ) ) );
3661 }
3662 }
3663
3664 avatar &you = get_avatar();
3665 if( is_armor() && you.has_trait( trait_WOOLALLERGY ) &&
3666 ( made_of( material_id( "wool" ) ) || has_own_flag( "wooled" ) ) ) {
3667 info.push_back( iteminfo( "DESCRIPTION",
3668 _( "* This clothing will give you an <bad>allergic "
3669 "reaction</bad>." ) ) );
3670 }
3671
3672 if( parts->test( iteminfo_parts::DESCRIPTION_FLAGS ) ) {
3673 // concatenate base and acquired flags...
3674 std::vector<std::string> flags;
3675 std::set_union( type->get_flags().begin(), type->get_flags().end(),
3676 get_flags().begin(), get_flags().end(),
3677 std::back_inserter( flags ) );
3678
3679 // ...and display those which have an info description
3680 for( const std::string &e : flags ) {
3681 const json_flag &f = json_flag::get( e );
3682 if( !f.info().empty() ) {
3683 info.emplace_back( "DESCRIPTION", string_format( "* %s", _( f.info() ) ) );
3684 }
3685 }
3686 }
3687
3688 armor_fit_info( info, parts, batch, debug );
3689
3690 if( is_tool() ) {
3692 info.push_back( iteminfo( "DESCRIPTION",
3693 _( "* This tool can draw power from a <info>Bionic Armor Interface</info>" ) ) );
3694 }
3696 info.push_back( iteminfo( "DESCRIPTION",
3697 _( "* This tool uses a <info>universal power supply</info> "
3698 "and is <neutral>not compatible</neutral> with "
3699 "<info>standard batteries</info>." ) ) );
3700 } else if( has_flag( flag_RECHARGE ) && has_flag( flag_NO_RELOAD ) &&
3702 info.push_back( iteminfo( "DESCRIPTION",
3703 _( "* This tool has a <info>rechargeable power cell</info> "
3704 "and is <neutral>not compatible</neutral> with "
3705 "<info>standard batteries</info>." ) ) );
3706 } else if( has_flag( flag_RECHARGE ) &&
3708 info.push_back( iteminfo( "DESCRIPTION",
3709 _( "* This tool has a <info>rechargeable power cell</info> "
3710 "and can be recharged in any <neutral>UPS-compatible "
3711 "recharging station</neutral>. You could charge it with "
3712 "<info>standard batteries</info>, but unloading it is "
3713 "impossible." ) ) );
3714 } else if( has_flag( flag_USES_BIONIC_POWER ) ) {
3715 info.emplace_back( "DESCRIPTION",
3716 _( "* This tool <info>runs on bionic power</info>." ) );
3717 }
3718 }
3719
3722 if( has_flag( flag_RADIO_MOD ) ) {
3723 info.emplace_back( "DESCRIPTION",
3724 _( "* This item has been modified to listen to <info>radio "
3725 "signals</info>. It can still be activated manually." ) );
3726 } else {
3727 info.emplace_back( "DESCRIPTION",
3728 _( "* This item can only be activated by a <info>radio "
3729 "signal</info>." ) );
3730 }
3731
3732 std::string signame;
3733 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
3734 signame = "<color_c_red>red</color> radio signal.";
3735 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
3736 signame = "<color_c_blue>blue</color> radio signal.";
3737 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
3738 signame = "<color_c_green>green</color> radio signal.";
3739 }
3741 info.emplace_back( "DESCRIPTION",
3742 string_format( _( "* It will be activated by the %s." ),
3743 signame ) );
3744 }
3745
3748 info.emplace_back( "DESCRIPTION",
3749 _( "* Activating this item with a <info>radio signal</info> will "
3750 "<neutral>detonate</neutral> it immediately." ) );
3751 }
3752 }
3753
3754 bionic_info( info, parts, batch, debug );
3755
3756 if( is_gun() && has_flag( flag_FIRE_TWOHAND ) &&
3758 info.push_back( iteminfo( "DESCRIPTION",
3759 _( "* This weapon needs <info>two free hands</info> "
3760 "to fire." ) ) );
3761 }
3762
3765 info.push_back( iteminfo( "DESCRIPTION",
3766 _( "* This mod <bad>obscures sights</bad> of the "
3767 "base weapon." ) ) );
3768 }
3769
3770 if( is_gunmod() && has_flag( flag_CONSUMABLE ) &&
3772 info.push_back( iteminfo( "DESCRIPTION",
3773 _( "* This mod might <bad>suffer wear</bad> when firing "
3774 "the base weapon." ) ) );
3775 }
3776
3779 info.push_back( iteminfo( "DESCRIPTION",
3780 _( "* The casing of this item has <neutral>cracked</neutral>, "
3781 "revealing an <info>ominous green glow</info>." ) ) );
3782 }
3783
3786 info.push_back( iteminfo( "DESCRIPTION",
3787 _( "* This object is <neutral>surrounded</neutral> by a "
3788 "<info>sickly green glow</info>." ) ) );
3789 }
3790
3791 if( is_brewable() || ( !contents.empty() && contents.front().is_brewable() ) ) {
3792 const item &brewed = !is_brewable() ? contents.front() : *this;
3794 const time_duration btime = brewed.brewing_time();
3795 int btime_i = to_days<int>( btime );
3796 if( btime <= 2_days ) {
3797 btime_i = to_hours<int>( btime );
3798 info.push_back( iteminfo( "DESCRIPTION",
3799 string_format( vgettext( "* Once set in a vat, this "
3800 "will ferment in around %d hour.",
3801 "* Once set in a vat, this will ferment in "
3802 "around %d hours.", btime_i ), btime_i ) ) );
3803 } else {
3804 info.push_back( iteminfo( "DESCRIPTION",
3805 string_format( vgettext( "* Once set in a vat, this "
3806 "will ferment in around %d day.",
3807 "* Once set in a vat, this will ferment in "
3808 "around %d days.", btime_i ), btime_i ) ) );
3809 }
3810 }
3812 for( const itype_id &res : brewed.brewing_results() ) {
3813 info.push_back( iteminfo( "DESCRIPTION",
3814 string_format( _( "* Fermenting this will produce "
3815 "<neutral>%s</neutral>." ),
3816 nname( res, brewed.charges ) ) ) );
3817 }
3818 }
3819 }
3820
3822 for( const fault_id &e : faults ) {
3823 //~ %1$s is the name of a fault and %2$s is the description of the fault
3824 info.emplace_back( "DESCRIPTION", string_format( _( "* <bad>%1$s</bad>. %2$s" ),
3825 e.obj().name(), e.obj().description() ) );
3826 }
3827 }
3828
3829 // does the item fit in any holsters?
3830 std::vector<const itype *> holsters = item_controller->find( [this]( const itype & e ) {
3831 if( !e.can_use( "holster" ) ) {
3832 return false;
3833 }
3834 const holster_actor *ptr = dynamic_cast<const holster_actor *>
3835 ( e.get_use( "holster" )->get_actor_ptr() );
3836 return ptr->can_holster( *this );
3837 } );
3838
3839 if( !holsters.empty() && parts->test( iteminfo_parts::DESCRIPTION_HOLSTERS ) ) {
3841 info.emplace_back( "DESCRIPTION", _( "<bold>Can be stored in</bold>: " ) +
3842 enumerate_as_string( holsters.begin(), holsters.end(),
3843 []( const itype * e ) {
3844 return e->nname( 1 );
3845 } ) );
3846 }
3847
3849 for( auto &u : type->use_methods ) {
3850 const delayed_transform_iuse *tt = dynamic_cast<const delayed_transform_iuse *>
3851 ( u.second.get_actor_ptr() );
3852 if( tt == nullptr ) {
3853 continue;
3854 }
3855 const int time_to_do = tt->time_to_do( *this );
3856 if( time_to_do <= 0 ) {
3857 info.push_back( iteminfo( "DESCRIPTION",
3858 _( "It's done and <info>can be activated</info>." ) ) );
3859 } else {
3860 const std::string time = to_string_clipped( time_duration::from_turns( time_to_do ) );
3861 info.push_back( iteminfo( "DESCRIPTION",
3862 string_format( _( "It will be done in %s." ),
3863 time.c_str() ) ) );
3864 }
3865 }
3866 }
3867
3868 std::map<std::string, std::string>::const_iterator item_note = item_vars.find( "item_note" );
3869 std::map<std::string, std::string>::const_iterator item_note_tool =
3870 item_vars.find( "item_note_tool" );
3871
3872 if( item_note != item_vars.end() && parts->test( iteminfo_parts::DESCRIPTION_NOTES ) ) {
3874 std::string ntext;
3875 const inscribe_actor *use_actor = nullptr;
3876 if( item_note_tool != item_vars.end() ) {
3877 const use_function *use_func = itype_id( item_note_tool->second )->get_use( "inscribe" );
3878 use_actor = dynamic_cast<const inscribe_actor *>( use_func->get_actor_ptr() );
3879 }
3880 if( use_actor ) {
3881 //~ %1$s: gerund (e.g. carved), %2$s: item name, %3$s: inscription text
3882 ntext = string_format( pgettext( "carving", "%1$s on the %2$s is: %3$s" ),
3883 use_actor->gerund, tname(), item_note->second );
3884 } else {
3885 //~ %1$s: inscription text
3886 ntext = string_format( pgettext( "carving", "Note: %1$s" ), item_note->second );
3887 }
3888 info.push_back( iteminfo( "DESCRIPTION", ntext ) );
3889 }
3890
3891 if( this->get_var( "die_num_sides", 0 ) != 0 ) {
3892 info.emplace_back( "DESCRIPTION",
3893 string_format( _( "* This item can be used as a <info>die</info>, "
3894 "and has <info>%d</info> sides." ),
3895 static_cast<int>( this->get_var( "die_num_sides",
3896 0 ) ) ) );
3897 }
3898
3899 // Price and barter value
3900 const int price_preapoc = price( false ) * batch;
3901 const int price_postapoc = price( true ) * batch;
3902 if( parts->test( iteminfo_parts::BASE_PRICE ) ) {
3904 info.push_back( iteminfo( "BASE", _( "Price: " ), _( "$<num>" ),
3906 static_cast<double>( price_preapoc ) / 100 ) );
3907 }
3908 if( price_preapoc != price_postapoc && parts->test( iteminfo_parts::BASE_BARTER ) ) {
3909 info.push_back( iteminfo( "BASE", space + _( "Barter value: " ), _( "$<num>" ),
3911 static_cast<double>( price_postapoc ) / 100 ) );
3912 }
3913
3914 // Recipes using this item as an ingredient
3916 itype_id tid = contents.empty() ? typeId() : contents.front().typeId();
3917 const inventory &crafting_inv = you.crafting_inventory();
3918
3919 const recipe_subset available_recipe_subset = you.get_available_recipes( crafting_inv, nullptr,
3921 const std::set<const recipe *> &item_recipes = available_recipe_subset.of_component( tid );
3922
3923 if( item_recipes.empty() ) {
3925 info.push_back( iteminfo( "DESCRIPTION",
3926 _( "You know of nothing you could craft with it." ) ) );
3927 } else {
3928 if( item_recipes.size() > 24 ) {
3930 info.push_back( iteminfo( "DESCRIPTION",
3931 _( "You know dozens of things you could craft with it." ) ) );
3932 } else if( item_recipes.size() > 12 ) {
3934 info.push_back( iteminfo( "DESCRIPTION",
3935 _( "You could use it to craft various other things." ) ) );
3936 } else {
3937 // Extract item names from recipes and sort them
3938 std::vector<std::pair<std::string, bool>> result_names;
3940 item_recipes.begin(), item_recipes.end(),
3941 std::back_inserter( result_names ),
3942 [&crafting_inv]( const recipe * r ) {
3943 bool can_make = r->deduped_requirements().can_make_with_inventory(
3944 crafting_inv, r->get_component_filter() );
3945 return std::make_pair( r->result_name(), can_make );
3946 } );
3947 std::sort( result_names.begin(), result_names.end(), localized_compare );
3948 const std::string recipes =
3949 enumerate_as_string( result_names.begin(), result_names.end(),
3950 []( const std::pair<std::string, bool> &p ) {
3951 if( p.second ) {
3952 return p.first;
3953 } else {
3954 return string_format( "<dark>%s</dark>", p.first );
3955 }
3956 } );
3958 info.push_back( iteminfo( "DESCRIPTION",
3959 string_format( _( "You could use it to craft: %s" ),
3960 recipes ) ) );
3961 }
3962 }
3963 }
3964 if( get_option<bool>( "ENABLE_ASCII_ART_ITEM" ) ) {
3965 const ascii_art_id art = type->picture_id;
3966 if( art.is_valid() ) {
3967 for( const std::string &line : art->picture ) {
3968 info.push_back( iteminfo( "DESCRIPTION", line ) );
3969 }
3970 }
3971 }
3972}
static std::string to_string_clipped(const int num, const clipped_unit type, const clipped_align align)
Definition: calendar.cpp:228
const inventory & crafting_inventory(bool clear_path)
Definition: crafting.cpp:556
std::vector< std::string > picture
Definition: ascii_art.h:22
iterator begin() const
Definition: flat_set.h:83
iterator end() const
Definition: flat_set.h:86
This is a iuse_transform that uses the age of the item instead of a counter.
Definition: iuse_actor.h:289
int time_to_do(const item &it) const
How much longer (in turns) until the transformation can be done, can be negative.
Definition: iuse_actor.cpp:882
Writes on stuff (ground or items)
Definition: iuse_actor.h:610
translation gerund
Definition: iuse_actor.h:633
const FlagsSetType & get_flags() const
returs read-only set of flags of this item (not including flags from item type or gunmods)
Definition: item.cpp:5361
const std::vector< itype_id > & brewing_results() const
The results of fermenting this item.
Definition: item.cpp:5959
std::set< fault_id > faults
What faults (if any) currently apply to this item.
Definition: item.h:2168
time_duration brewing_time() const
Time for this item to be fully fermented.
Definition: item.cpp:5954
bool conductive() const
Whether the items is conductive.
Definition: item.cpp:6486
void bionic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3278
int price(bool practical) const
Returns the monetary value of an item.
Definition: item.cpp:4929
void armor_fit_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2743
Definition: flag.h:15
std::string info() const
Get informative text for display in UI.
Definition: flag.h:30
recipe_subset get_available_recipes(const inventory &crafting_inv, const std::vector< npc * > *helpers=nullptr, recipe_filter filter=nullptr) const
Returns all available recipes (from books and npc companions)
Definition: player.cpp:297
const std::set< const recipe * > & of_component(const itype_id &id) const
Returns all recipes which could use component.
static const std::string flag_RADIOSIGNAL_2("RADIOSIGNAL_2")
static const std::string flag_FIRE_TWOHAND("FIRE_TWOHAND")
static const std::string flag_RADIOSIGNAL_1("RADIOSIGNAL_1")
static const std::string flag_DISABLE_SIGHTS("DISABLE_SIGHTS")
static const std::string flag_USE_UPS("USE_UPS")
static const std::string flag_RECHARGE("RECHARGE")
static const std::string flag_RADIO_ACTIVATION("RADIO_ACTIVATION")
static const std::string flag_RADIO_INVOKE_PROC("RADIO_INVOKE_PROC")
static const std::string flag_CONSUMABLE("CONSUMABLE")
static const std::string flag_NO_RELOAD("NO_RELOAD")
static const std::string flag_RADIOSIGNAL_3("RADIOSIGNAL_3")
static const std::string flag_LEAK_ALWAYS("LEAK_ALWAYS")
static const std::string flag_RADIO_MOD("RADIO_MOD")
std::unique_ptr< Item_factory > item_controller
@ DESCRIPTION_RECHARGE_UPSCAPABLE
@ DESCRIPTION_GUNMOD_DISABLESSIGHTS
@ DESCRIPTION_BREWABLE_DURATION
@ DESCRIPTION_RADIO_ACTIVATION_CHANNEL
@ DESCRIPTION_BREWABLE_PRODUCTS
@ DESCRIPTION_RECHARGE_NORELOAD
@ DESCRIPTION_ACTIVATABLE_TRANSFORMATION
@ DESCRIPTION_BIONIC_ARMOR_INTERFACE
@ DESCRIPTION_RADIOACTIVITY_DAMAGED
@ DESCRIPTION_RADIO_ACTIVATION_PROC
@ DESCRIPTION_RECHARGE_UPSMODDED
@ DESCRIPTION_GUNMOD_CONSUMABLE
@ DESCRIPTION_RADIOACTIVITY_ALWAYS
@ DESCRIPTION_RADIO_ACTIVATION
@ DESCRIPTION_APPLICABLE_RECIPES
void line(map *m, const ter_id &type, point p1, point p2)
Definition: mapgen.cpp:6281
void transform(player &p, const tripoint &pos)
Transform the examined object into the object specified by its transforms_into property.
Definition: iexamine.cpp:1641
recipe_filter recipe_filter_by_component(const itype_id &c)
ascii_art_id picture_id
Definition: itype.h:909
constexpr localized_comparator localized_compare
Definition: translations.h:342

References _, armor_fit_info(), BASE_BARTER, BASE_PRICE, BASE_RIGIDITY, cata::flat_set< T, Compare, Data >::begin(), bionic_info(), brewing_results(), brewing_time(), itype::can_use(), charges, conductive(), contents, Character::crafting_inventory(), damage(), debug, DESCRIPTION_ACTIVATABLE_TRANSFORMATION, DESCRIPTION_APPLICABLE_RECIPES, DESCRIPTION_BIONIC_ARMOR_INTERFACE, DESCRIPTION_BREWABLE_DURATION, DESCRIPTION_BREWABLE_PRODUCTS, DESCRIPTION_CONDUCTIVITY, DESCRIPTION_FAULTS, DESCRIPTION_FLAGS, DESCRIPTION_GUNMOD_CONSUMABLE, DESCRIPTION_GUNMOD_DISABLESSIGHTS, DESCRIPTION_HOLSTERS, DESCRIPTION_NOTES, DESCRIPTION_RADIO_ACTIVATION, DESCRIPTION_RADIO_ACTIVATION_CHANNEL, DESCRIPTION_RADIO_ACTIVATION_PROC, DESCRIPTION_RADIOACTIVITY_ALWAYS, DESCRIPTION_RADIOACTIVITY_DAMAGED, DESCRIPTION_RECHARGE_NORELOAD, DESCRIPTION_RECHARGE_UPSCAPABLE, DESCRIPTION_RECHARGE_UPSMODDED, DESCRIPTION_TWOHANDED, item_contents::empty(), cata::flat_set< T, Compare, Data >::end(), enumerate_as_string(), faults, flag_CONDUCTIVE(), flag_CONSUMABLE(), flag_DISABLE_SIGHTS(), flag_FIRE_TWOHAND(), flag_LEAK_ALWAYS(), flag_LEAK_DAM(), flag_NO_RELOAD(), flag_RADIO_ACTIVATION(), flag_RADIO_INVOKE_PROC(), flag_RADIO_MOD(), flag_RADIOACTIVE(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_RECHARGE(), flag_USE_UPS(), flag_USES_BIONIC_POWER(), time_duration::from_turns(), item_contents::front(), inscribe_actor::gerund, json_flag::get(), use_function::get_actor_ptr(), player::get_available_recipes(), get_avatar(), get_flags(), itype::get_flags(), itype::get_use(), get_var(), has_flag(), has_own_flag(), Character::has_trait(), json_flag::info(), info(), insert_separation_line(), is_armor(), is_brewable(), iteminfo::is_decimal, is_gun(), is_gunmod(), is_null(), is_power_armor(), is_tool(), item_controller, item_vars, itype_id, localized_compare, iteminfo::lower_is_better, made_of(), nname(), iteminfo::no_newline, recipe_subset::of_component(), pgettext(), price(), ptr(), recipe_filter_by_component(), itype::rigid, sign::space, string_format(), iteminfo_query::test(), time, delayed_transform_iuse::time_to_do(), tname(), to_string_clipped(), trait_WOOLALLERGY, iexamine::transform(), type, typeId(), itype::use_methods, and vgettext().

Referenced by info().

◆ find_armor_data()

const islot_armor * item::find_armor_data ( ) const

If this is an armor item, return its armor data.

You should probably not use this function, use the various functions above (like get_storage) to access armor data directly.

Definition at line 6690 of file item.cpp.

6691{
6692 if( type->armor ) {
6693 return &*type->armor;
6694 }
6695 // Currently the only way to make a non-armor item into armor is to install a gun mod.
6696 // The gunmods are stored in the items contents, as are the contents of a container, and the
6697 // tools in a tool belt (a container actually), or the ammo in a quiver (container again).
6698 for( const item *mod : gunmods() ) {
6699 if( mod->type->armor ) {
6700 return &*mod->type->armor;
6701 }
6702 }
6703 return nullptr;
6704}
cata::value_ptr< islot_armor > armor
Definition: itype.h:852

References itype::armor, gunmods(), and type.

Referenced by get_base_env_resist(), get_base_env_resist_w_filter(), get_coverage(), get_covered_body_parts(), get_encumber(), get_encumber_when_containing(), get_env_resist(), get_storage(), get_thickness(), get_warmth(), get_weight_capacity_bonus(), get_weight_capacity_modifier(), is_armor(), and is_sided().

◆ fire_resist()

int item::fire_resist ( bool  to_self = false,
int  base_env_resist = 0 
) const

Definition at line 6169 of file item.cpp.

6170{
6171 if( to_self ) {
6172 // Fire damages items in a different way
6173 return INT_MAX;
6174 }
6175
6176 float resist = 0.0;
6178 if( is_null() ) {
6179 return 0.0;
6180 }
6181
6182 const std::vector<const material_type *> mat_types = made_of_types();
6183 if( !mat_types.empty() ) {
6184 for( const material_type *mat : mat_types ) {
6185 resist += mat->fire_resist();
6186 }
6187 // Average based on number of materials.
6188 resist /= mat_types.size();
6189 }
6190
6191 const int env = get_env_resist( base_env_resist );
6192 if( env < 10 ) {
6193 // Iron resists immersion in magma, iron-clad knight won't.
6194 resist *= env / 10.0f;
6195 }
6196
6197 return std::lround( resist + mod );
6198}
@ clothing_mod_type_fire
Definition: clothing_mod.h:18

References clothing_mod_type_fire, get_clothing_mod_val(), get_env_resist(), is_null(), and made_of_types().

Referenced by armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), damage_resist(), and sew_advanced_actor::use().

◆ flammable()

bool item::flammable ( int  threshold = 0) const

Whether the items is flammable.

(Make sure to keep this in sync with fire code in fields.cpp)

Parameters
thresholdItem is flammable if it provides more fuel than threshold.

Definition at line 8329 of file item.cpp.

8330{
8331 const std::vector<const material_type *> &mats = made_of_types();
8332 if( mats.empty() ) {
8333 // Don't know how to burn down something made of nothing.
8334 return false;
8335 }
8336
8337 int flammability = 0;
8338 units::volume volume_per_turn = 0_ml;
8339 for( const material_type *m : mats ) {
8340 const mat_burn_data &bd = m->burn_data( 1 );
8341 if( bd.immune ) {
8342 // Made to protect from fire
8343 return false;
8344 }
8345
8346 flammability += bd.fuel;
8347 volume_per_turn += bd.volume_per_turn;
8348 }
8349
8350 if( threshold == 0 || flammability <= 0 ) {
8351 return flammability > 0;
8352 }
8353
8354 volume_per_turn /= mats.size();
8355 units::volume vol = base_volume();
8356 if( volume_per_turn > 0_ml && volume_per_turn < vol ) {
8357 flammability = flammability * volume_per_turn / vol;
8358 } else {
8359 // If it burns well, it provides a bonus here
8360 flammability *= vol / units::legacy_volume_factor;
8361 }
8362
8363 return flammability > threshold;
8364}
Contains burning parameters for a given material.
Definition: fire.h:46
bool immune
If this is true, an object will not burn or be destroyed by fire.
Definition: fire.h:48
units::volume volume_per_turn
If non-zero and lower than item's volume, scale burning by volume_penalty / volume.
Definition: fire.h:50
float fuel
Fuel contributed per tick when this material burns.
Definition: fire.h:52

References base_volume(), mat_burn_data::fuel, mat_burn_data::immune, units::legacy_volume_factor, made_of_types(), and mat_burn_data::volume_per_turn.

Referenced by Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), and monster::process_turn().

◆ food_info()

void item::food_info ( const item food_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug,
temperature_flag  temperature 
) const
Survival >=3 allows detection of poisonous food Survival >=5 allows detection of hallucinogenic food

Definition at line 1673 of file item.cpp.

1676{
1677 nutrients min_nutr;
1678 nutrients max_nutr;
1679 avatar &you = get_avatar();
1680
1681 std::string recipe_exemplar = get_var( "recipe_exemplar", "" );
1682 if( recipe_exemplar.empty() ) {
1683 min_nutr = max_nutr = you.compute_effective_nutrients( *food_item );
1684 } else {
1685 std::tie( min_nutr, max_nutr ) =
1686 you.compute_nutrient_range( *food_item, recipe_id( recipe_exemplar ) );
1687 }
1688
1689 bool show_nutr = parts->test( iteminfo_parts::FOOD_NUTRITION ) ||
1691 if( min_nutr != max_nutr && show_nutr ) {
1692 info.emplace_back(
1693 "FOOD", _( "Nutrition will <color_cyan>vary with chosen ingredients</color>." ) );
1694 if( recipe_dict.is_item_on_loop( food_item->typeId() ) ) {
1695 info.emplace_back(
1696 "FOOD", _( "Nutrition range cannot be calculated accurately due to "
1697 "<color_red>recipe loops</color>." ) );
1698 }
1699 }
1700
1701 const std::string space = " ";
1702 if( max_nutr.kcal != 0 || food_item->get_comestible()->quench != 0 ) {
1703 if( parts->test( iteminfo_parts::FOOD_NUTRITION ) ) {
1704 info.push_back( iteminfo( "FOOD", _( "<bold>Calories (kcal)</bold>: " ),
1705 "", iteminfo::no_newline, min_nutr.kcal ) );
1706 if( max_nutr.kcal != min_nutr.kcal ) {
1707 info.push_back( iteminfo( "FOOD", _( "-" ),
1708 "", iteminfo::no_newline, max_nutr.kcal ) );
1709 }
1710 }
1711 if( parts->test( iteminfo_parts::FOOD_QUENCH ) ) {
1712 info.push_back( iteminfo( "FOOD", space + _( "Quench: " ),
1713 food_item->get_comestible()->quench ) );
1714 }
1715 }
1716
1717 const std::pair<int, int> fun_for_food_item = you.fun_for( *food_item );
1718 if( fun_for_food_item.first != 0 && parts->test( iteminfo_parts::FOOD_JOY ) ) {
1719 info.push_back( iteminfo( "FOOD", _( "Enjoyability: " ), fun_for_food_item.first ) );
1720 }
1721
1722 if( parts->test( iteminfo_parts::FOOD_PORTIONS ) ) {
1723 info.push_back( iteminfo( "FOOD", _( "Portions: " ),
1724 std::abs( static_cast<int>( food_item->charges ) * batch ) ) );
1725 }
1726 if( food_item->corpse != nullptr && parts->test( iteminfo_parts::FOOD_SMELL ) &&
1727 ( debug || ( g != nullptr && ( you.has_trait( trait_CARNIVORE ) ||
1729 info.push_back( iteminfo( "FOOD", _( "Smells like: " ) + food_item->corpse->nname() ) );
1730 }
1731
1732 auto format_vitamin = [&]( const std::pair<vitamin_id, int> &v, bool display_vitamins ) {
1733 const bool is_vitamin = v.first->type() == vitamin_type::VITAMIN;
1734 // only display vitamins that we actually require
1735 if( you.vitamin_rate( v.first ) == 0_turns || v.second == 0 ||
1736 display_vitamins != is_vitamin || v.first->has_flag( flag_NO_DISPLAY ) ) {
1737 return std::string();
1738 }
1739 const double multiplier = you.vitamin_rate( v.first ) / 1_days * 100;
1740 const int min_value = min_nutr.get_vitamin( v.first );
1741 const int max_value = v.second;
1742 const int min_rda = std::lround( min_value * multiplier );
1743 const int max_rda = std::lround( max_value * multiplier );
1744 const std::string format = min_rda == max_rda ? "%s (%i%%)" : "%s (%i-%i%%)";
1745 return string_format( format, v.first->name(), min_value, max_value );
1746 };
1747
1748 const auto max_nutr_vitamins = sorted_lex( max_nutr.vitamins );
1749 const std::string required_vits = enumerate_as_string(
1750 max_nutr_vitamins.begin(),
1751 max_nutr_vitamins.end(),
1752 [&]( const std::pair<vitamin_id, int> &v ) {
1753 return format_vitamin( v, true );
1754 } );
1755
1756 const std::string effect_vits = enumerate_as_string(
1757 max_nutr_vitamins.begin(),
1758 max_nutr_vitamins.end(),
1759 [&]( const std::pair<vitamin_id, int> &v ) {
1760 return format_vitamin( v, false );
1761 } );
1762
1763 if( !required_vits.empty() && parts->test( iteminfo_parts::FOOD_VITAMINS ) ) {
1764 info.emplace_back( "FOOD", _( "Vitamins (RDA): " ), required_vits );
1765 }
1766
1767 if( !effect_vits.empty() && parts->test( iteminfo_parts::FOOD_VIT_EFFECTS ) ) {
1768 info.emplace_back( "FOOD", _( "Other contents: " ), effect_vits );
1769 }
1770
1772
1773 if( you.allergy_type( *food_item ) != morale_type( "morale_null" ) ) {
1774 info.emplace_back( "DESCRIPTION",
1775 _( "* This food will cause an <bad>allergic reaction</bad>." ) );
1776 }
1777
1778 if( food_item->has_flag( flag_CANNIBALISM ) &&
1780 if( !you.has_trait_flag( trait_flag_CANNIBAL ) ) {
1781 info.emplace_back( "DESCRIPTION",
1782 _( "* This food contains <bad>human flesh</bad>." ) );
1783 } else {
1784 info.emplace_back( "DESCRIPTION",
1785 _( "* This food contains <good>human flesh</good>." ) );
1786 }
1787 }
1788
1789 if( food_item->is_tainted() && parts->test( iteminfo_parts::FOOD_CANNIBALISM ) ) {
1790 info.emplace_back( "DESCRIPTION",
1791 _( "* This food is <bad>tainted</bad> and will poison you." ) );
1792 }
1793
1794 ///\EFFECT_SURVIVAL >=3 allows detection of poisonous food
1795 if( food_item->has_flag( flag_HIDDEN_POISON ) && you.get_skill_level( skill_survival ) >= 3 &&
1796 parts->test( iteminfo_parts::FOOD_POISON ) ) {
1797 info.emplace_back( "DESCRIPTION",
1798 _( "* On closer inspection, this appears to be "
1799 "<bad>poisonous</bad>." ) );
1800 }
1801
1802 ///\EFFECT_SURVIVAL >=5 allows detection of hallucinogenic food
1803 if( food_item->has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 &&
1805 info.emplace_back( "DESCRIPTION",
1806 _( "* On closer inspection, this appears to be "
1807 "<neutral>hallucinogenic</neutral>." ) );
1808 }
1809
1810 if( food_item->goes_bad() && parts->test( iteminfo_parts::FOOD_ROT ) ) {
1811 const std::string rot_time = to_string_clipped( food_item->get_shelf_life() );
1812 info.emplace_back( "DESCRIPTION",
1813 string_format( _( "* This food is <neutral>perishable</neutral>, "
1814 "and at room temperature has an estimated nominal "
1815 "shelf life of <info>%s</info>." ), rot_time ) );
1816
1817
1818 if( parts->test( iteminfo_parts::FOOD_ROT_STORAGE ) ) {
1819 const char *temperature_description;
1820 bool print_freshness_duration = false;
1821 // There should be a better way to do this...
1822 switch( temperature ) {
1825 temperature_description = _( "* Current storage conditions <bad>do not</bad> "
1826 "protect this item from rot." );
1827 }
1828 break;
1831 temperature_description = _( "* Current storage conditions <neutral>partially</neutral> "
1832 "protect this item from rot. It will stay fresh at least <info>%s</info>." );
1833 print_freshness_duration = true;
1834 }
1835 break;
1837 temperature_description = _( "* Current storage conditions <good>fully</good> "
1838 "protect this item from rot. It will stay fresh indefinitely." );
1839 }
1840 break;
1841 default: {
1842 temperature_description = "BUGGED TEMPERATURE INFO";
1843 }
1844 }
1845
1846 if( print_freshness_duration ) {
1847 time_duration remaining_fresh = food_item->minimum_freshness_duration( temperature );
1848 std::string time_string = to_string_clipped( remaining_fresh );
1849 info.emplace_back( "DESCRIPTION", string_format( temperature_description, time_string ) );
1850 } else {
1851 info.emplace_back( "DESCRIPTION", temperature_description );
1852 }
1853 }
1854
1855 if( !food_item->rotten() ) {
1856 info.emplace_back( "DESCRIPTION", get_freshness_description( *food_item ) );
1857 }
1858
1859 if( food_item->has_flag( flag_NO_PARASITES ) ) {
1860 info.emplace_back( "DESCRIPTION",
1861 _( "* It seems that deep freezing <good>killed all "
1862 "parasites</good>." ) );
1863 }
1864 if( food_item->rotten() ) {
1865 if( you.has_bionic( bio_digestion ) ) {
1866 info.push_back( iteminfo( "DESCRIPTION",
1867 _( "This food has started to <neutral>rot</neutral>, "
1868 "but <info>your bionic digestion can tolerate "
1869 "it</info>." ) ) );
1870 } else if( you.has_trait( trait_SAPROVORE ) ) {
1871 info.push_back( iteminfo( "DESCRIPTION",
1872 _( "This food has started to <neutral>rot</neutral>, "
1873 "but <info>you can tolerate it</info>." ) ) );
1874 } else {
1875 info.push_back( iteminfo( "DESCRIPTION",
1876 _( "This food has started to <bad>rot</bad>. "
1877 "<info>Eating</info> it would be a <bad>very bad "
1878 "idea</bad>." ) ) );
1879 }
1880 }
1881 }
1882}
bool has_trait_flag(const std::string &b) const
Returns true if player has a trait with a flag.
Definition: mutation.cpp:106
virtual bool has_artifact_with(art_effect_passive effect) const
Definition: character.cpp:3214
nutrients compute_effective_nutrients(const item &) const
std::pair< nutrients, nutrients > compute_nutrient_range(const item &, const recipe_id &, const cata::flat_set< std::string > &extra_flags={}) const
Get calorie & vitamin contents for a comestible, taking into account character traits.
time_duration vitamin_rate(const vitamin_id &vit) const
Get vitamin usage rate (minutes per unit) accounting for bionics, mutations and effects.
std::pair< int, int > fun_for(const item &comest) const
Handles the enjoyability value for a comestible.
bool rotten() const
returns true if item is now rotten after all shelf life has elapsed
Definition: item.h:850
time_duration minimum_freshness_duration(temperature_flag temperature) const
Time that this item is guaranteed to stay fresh.
Definition: item.cpp:5708
const cata::value_ptr< islot_comestible > & get_comestible() const
Definition: item.cpp:10145
bool is_tainted() const
Is item derived from a zombie?
Definition: item.cpp:9838
bool is_item_on_loop(const itype_id &) const
@ AEP_SUPER_CLAIRVOYANCE
Definition: enums.h:112
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_NO_DISPLAY("NO_DISPLAY")
static const bionic_id bio_digestion("bio_digestion")
static const trait_id trait_CARNIVORE("CARNIVORE")
static const std::string flag_CANNIBALISM("CANNIBALISM")
static const std::string flag_HIDDEN_HALLU("HIDDEN_HALLU")
static const trait_id trait_SAPROVORE("SAPROVORE")
static const std::string flag_NO_PARASITES("NO_PARASITES")
static const std::string trait_flag_CANNIBAL("CANNIBAL")
static const skill_id skill_survival("survival")
static std::string get_freshness_description(const item &food_item)
Definition: item.cpp:1114
constexpr T max_value()
recipe_dictionary recipe_dict
int kcal
amount of kcal this food has
Definition: stomach.h:18
std::map< vitamin_id, int > vitamins
vitamins potentially provided by this comestible (if any)
Definition: stomach.h:21
int get_vitamin(const vitamin_id &) const
Definition: stomach.cpp:42
string_id< recipe > recipe_id
Definition: type_id.h:143
@ VITAMIN
Definition: vitamin.h:19

References _, AEP_SUPER_CLAIRVOYANCE, Character::allergy_type(), bio_digestion, charges, Character::compute_effective_nutrients(), Character::compute_nutrient_range(), corpse, debug, enumerate_as_string(), flag_CANNIBALISM(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_NO_DISPLAY(), flag_NO_PARASITES(), FOOD_CANNIBALISM, FOOD_HALLUCINOGENIC, FOOD_JOY, FOOD_NUTRITION, FOOD_POISON, FOOD_PORTIONS, FOOD_QUENCH, FOOD_ROT, FOOD_ROT_STORAGE, FOOD_SMELL, FOOD_VIT_EFFECTS, FOOD_VITAMINS, format(), Character::fun_for(), g, get_avatar(), get_comestible(), get_freshness_description(), get_shelf_life(), Character::get_skill_level(), get_var(), nutrients::get_vitamin(), goes_bad(), Character::has_artifact_with(), Character::has_bionic(), has_flag(), Character::has_trait(), Character::has_trait_flag(), info(), insert_separation_line(), recipe_dictionary::is_item_on_loop(), is_tainted(), nutrients::kcal, detail::max_value(), minimum_freshness_duration(), mtype::nname(), iteminfo::no_newline, recipe_dict, rotten(), skill_survival, sorted_lex(), sign::space, string_format(), TEMP_FREEZER, TEMP_FRIDGE, TEMP_HEATER, TEMP_NORMAL, TEMP_ROOT_CELLAR, iteminfo_query::test(), to_string_clipped(), trait_CARNIVORE, trait_flag_CANNIBAL(), trait_SAPROVORE, typeId(), VITAMIN, Character::vitamin_rate(), and nutrients::vitamins.

Referenced by info().

◆ fuel_energy()

float item::fuel_energy ( ) const

Returns energy of one charge of this item as fuel for an engine.

Definition at line 6824 of file item.cpp.

6825{
6826 return is_fuel() ? type->fuel->energy : 0.0f;
6827}
bool is_fuel() const
Definition: item.cpp:6768
cata::value_ptr< islot_fuel > fuel
Definition: itype.h:858

References itype::fuel, is_fuel(), and type.

Referenced by Character::burn_fuel(), vehicle_part::consume_energy(), vehicle::consume_fuel(), vehicle::consumption_per_hour(), Character::get_acquirable_energy(), game::on_move_effects(), and Character::passive_power_gen().

◆ fuel_pump_terrain()

std::string item::fuel_pump_terrain ( ) const

Returns the string of the id of the terrain that pumps this fuel, if any.

Definition at line 6829 of file item.cpp.

6830{
6831 return is_fuel() ? type->fuel->pump_terrain : "t_null";
6832}

References itype::fuel, is_fuel(), and type.

Referenced by map::place_gas_pump().

◆ get_available_recipes()

std::vector< std::pair< const recipe *, int > > item::get_available_recipes ( const player u) const

Enumerates recipes available from this book and the skill level required to use them.

Definition at line 7123 of file item.cpp.

7124{
7125 std::vector<std::pair<const recipe *, int>> recipe_entries;
7126 if( is_book() ) {
7127 for( const islot_book::recipe_with_description_t &elem : type->book->recipes ) {
7128 if( u.get_skill_level( elem.recipe->skill_used ) >= elem.skill_level ) {
7129 recipe_entries.push_back( std::make_pair( elem.recipe, elem.skill_level ) );
7130 }
7131 }
7132 } else if( has_var( "EIPC_RECIPES" ) ) {
7133 // See einkpc_download_memory_card() in iuse.cpp where this is set.
7134 const std::string recipes = get_var( "EIPC_RECIPES" );
7135 // Capture the index one past the delimiter, i.e. start of target string.
7136 size_t first_string_index = recipes.find_first_of( ',' ) + 1;
7137 while( first_string_index != std::string::npos ) {
7138 size_t next_string_index = recipes.find_first_of( ',', first_string_index );
7139 if( next_string_index == std::string::npos ) {
7140 break;
7141 }
7142 std::string new_recipe = recipes.substr( first_string_index,
7143 next_string_index - first_string_index );
7144 const recipe *r = &recipe_id( new_recipe ).obj();
7145 if( u.get_skill_level( r->skill_used ) >= r->difficulty ) {
7146 recipe_entries.push_back( std::make_pair( r, r->difficulty ) );
7147 }
7148 first_string_index = next_string_index + 1;
7149 }
7150 }
7151 return recipe_entries;
7152}
int difficulty
Definition: recipe.h:62

References itype::book, recipe::difficulty, Character::get_skill_level(), get_var(), has_var(), is_book(), string_id< T >::obj(), islot_book::recipe_with_description_t::recipe, islot_book::recipe_with_description_t::skill_level, recipe::skill_used, and type.

Referenced by avatar::do_read(), and player::get_recipes_from_books().

◆ get_base_env_resist_w_filter()

int item::get_base_env_resist_w_filter ( ) const

Returns the base resistance to environmental effects if an item (for example a gas mask) requires a gas filter to operate and this filter is installed.

Used in iuse::gasmask to change protection of a gas mask if it has (or don't has) filters. For other applications use get_env_resist() above.

Definition at line 5785 of file item.cpp.

5786{
5787 const islot_armor *t = find_armor_data();
5788 if( t == nullptr ) {
5789 return is_pet_armor() ? type->pet_armor->env_resist_w_filter : 0;
5790 }
5791 return t->env_resist_w_filter;
5792}
const islot_armor * find_armor_data() const
If this is an armor item, return its armor data.
Definition: item.cpp:6690
int env_resist_w_filter
Environmental protection of a gas mask with installed filter.
Definition: itype.h:267
cata::value_ptr< islot_pet_armor > pet_armor
Definition: itype.h:853

References islot_armor::env_resist_w_filter, find_armor_data(), is_pet_armor(), itype::pet_armor, and type.

Referenced by armor_protection_info(), iuse::dive_tank(), and iuse::gasmask().

◆ get_base_material()

const material_type & item::get_base_material ( ) const

Get the basic (main) material of this item.

May return the null-material.

Definition at line 7159 of file item.cpp.

7160{
7161 const std::vector<material_id> &mats = made_of();
7162 return mats.empty() ? material_id::NULL_ID().obj() : mats.front().obj();
7163}

References made_of(), string_id< material_type >::NULL_ID(), and string_id< T >::obj().

Referenced by Character::armor_absorb(), and durability_indicator().

◆ get_cable_target()

std::optional< tripoint > item::get_cable_target ( Character p,
const tripoint pos 
) const

Gets the point (vehicle tile) the cable is connected to.

Returns nothing if not connected to anything.

Definition at line 9363 of file item.cpp.

9364{
9365 const std::string &state = get_var( "state" );
9366 if( state != "pay_out_cable" && state != "cable_charger_link" ) {
9367 return std::nullopt;
9368 }
9369 map &here = get_map();
9370 const optional_vpart_position vp_pos = here.veh_at( pos );
9371 if( vp_pos ) {
9372 const std::optional<vpart_reference> seat = vp_pos.part_with_feature( "BOARDABLE", true );
9373 if( seat && p == seat->vehicle().get_passenger( seat->part_index() ) ) {
9374 return pos;
9375 }
9376 }
9377
9378 tripoint source( get_var( "source_x", 0 ), get_var( "source_y", 0 ), get_var( "source_z", 0 ) );
9379
9380 return here.getlocal( source );
9381}
Manage and cache data about a part of the map.
Definition: map.h:384
tripoint getlocal(const tripoint &p) const
Inverse of getabs.
Definition: map.cpp:8388
optional_vpart_position veh_at(const tripoint &p) const
Checks if tile is occupied by vehicle and by which part.
Definition: map.cpp:1073
Simple wrapper to forward functions that may return a std::optional to vpart_position.
std::optional< vpart_reference > part_with_feature(const std::string &f, bool unbroken) const
Definition: vehicle.cpp:2482

References get_map(), get_var(), map::getlocal(), optional_vpart_position::part_with_feature(), and map::veh_at().

Referenced by process_cable().

◆ get_cached_tool_selections()

const std::vector< comp_selection< tool_comp > > & item::get_cached_tool_selections ( ) const

Definition at line 10139 of file item.cpp.

10140{
10141 assert( craft_data_ );
10142 return craft_data_->cached_tool_selections;
10143}

References craft_data_.

◆ get_category()

const item_category & item::get_category ( ) const

Definition at line 8699 of file item.cpp.

8700{
8701 if( is_container() && !contents.empty() ) {
8702 return contents.front().get_category();
8703 }
8704
8705 static item_category null_category;
8706 return type->category_force.is_valid() ? type->category_force.obj() : null_category;
8707}
Contains metadata for one category of items.
Definition: item_category.h:35
item_category_id category_force
If set via JSON forces item category to this (preventing automatic assignment)
Definition: itype.h:1003

References itype::category_force, contents, item_contents::empty(), item_contents::front(), get_category(), is_container(), string_id< T >::is_valid(), string_id< T >::obj(), and type.

Referenced by inventory_selector::add_items(), basic_info(), json_talk_topic::gen_responses(), get_category(), inventory_entry::get_category_ptr(), zone_manager::get_near_zone_type_for_item(), is_map(), map_item_stack::map_item_stack_sort(), operator<(), conditional_t< T >::set_has_item_category(), and spoilage_sort_order().

◆ get_chapters()

int item::get_chapters ( ) const

How many chapters the book has (if any).

Will be 0 if the item is not a book, or if it has no chapters at all. Each reading will "consume" a chapter, if the book has no unread chapters, it's less fun.

Definition at line 7097 of file item.cpp.

7098{
7099 if( !type->book ) {
7100 return 0;
7101 }
7102 return type->book->chapters;
7103}

References itype::book, and type.

Referenced by display_name(), character_funcs::get_book_fun_for(), get_remaining_chapters(), and io().

◆ get_clothing_mod_val()

float item::get_clothing_mod_val ( clothing_mod_type  type) const

Definition at line 10164 of file item.cpp.

10165{
10167 type );
10168 return get_var( key, 0.0 );
10169}
static const std::string CLOTHING_MOD_VAR_PREFIX("clothing_mod_")
std::string string_from_clothing_mod_type(clothing_mod_type type)

References CLOTHING_MOD_VAR_PREFIX(), get_var(), clothing_mods::string_from_clothing_mod_type(), and type.

Referenced by acid_resist(), bash_resist(), bullet_resist(), cut_resist(), fire_resist(), get_encumber_when_containing(), get_storage(), and get_warmth().

◆ get_comestible()

◆ get_comestible_fun()

int item::get_comestible_fun ( ) const

Definition at line 5490 of file item.cpp.

5491{
5492 if( !is_comestible() ) {
5493 return 0;
5494 }
5495 int fun = get_comestible()->fun;
5496 for( const std::string &flag : item_tags ) {
5497 fun += json_flag::get( flag ).taste_mod();
5498 }
5499 for( const std::string &flag : type->get_flags() ) {
5500 fun += json_flag::get( flag ).taste_mod();
5501 }
5502
5503 return fun;
5504}
bool is_comestible() const
Definition: item.cpp:6595
int taste_mod() const
The flag's modifier on the fun value of comestibles.
Definition: flag.h:55

References json_flag::get(), get_comestible(), itype::get_flags(), is_comestible(), item_tags, json_flag::taste_mod(), and type.

Referenced by iuse::blech(), basecamp::distribute_food(), mattack::eat_food(), Character::fun_for(), med_info(), rate_food(), and npc::will_accept_from_player().

◆ get_contained()

const item & item::get_contained ( ) const

Return a contained item (if any and only one).

Definition at line 7059 of file item.cpp.

7060{
7061 if( contents.empty() ) {
7062 return null_item_reference();
7063 }
7064 return contents.front();
7065}
item & null_item_reference()
Returns a reference to a null item (see item::is_null).
Definition: item.cpp:325

References contents, item_contents::empty(), item_contents::front(), and null_item_reference().

Referenced by Character::consume_effects(), basecamp::distribute_food(), trading_window::get_var_trade(), Character::invoke_item(), examine_item_menu::rate_action_use(), ranged::throw_item(), try_consume(), avatar_funcs::use_item(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and npc::will_accept_from_player().

◆ get_container_capacity()

units::volume item::get_container_capacity ( ) const

It returns the total capacity (volume) of the container for liquids.

Definition at line 8409 of file item.cpp.

8410{
8411 if( !is_container() ) {
8412 return 0_ml;
8413 }
8414 return type->container->contains;
8415}

References itype::container, is_container(), and type.

Referenced by vehicle_part::ammo_capacity(), display_name(), get_remaining_capacity_for_liquid(), get_total_capacity(), is_funnel_container(), Item_factory::migrate_item(), Item_modifier::modify(), and ranged::throw_item().

◆ get_continue_reqs()

requirement_data item::get_continue_reqs ( ) const

Returns requirement data representing what is needed to resume work on an in progress craft.

Causes a debugmsg and returns empty requirement data if called on a non-craft

Returns
what is needed to continue craft, may be empty requirement data

Definition at line 975 of file crafting.cpp.

976{
977 if( !is_craft() ) {
978 debugmsg( "get_continue_reqs() called on non-craft '%s.' Aborting.", tname() );
979 return requirement_data();
980 }
982}
static requirement_data continue_requirements(const std::vector< item_comp > &required_comps, const std::list< item > &remaining_comps)
Returns the item requirements to continue an in progress craft with the passed components.

References components, requirement_data::continue_requirements(), craft_data_, debugmsg, is_craft(), and tname().

◆ get_corpse_name()

std::string item::get_corpse_name ( )

Returns name of deceased being if it had any or empty string if not.

Definition at line 9935 of file item.cpp.

9936{
9937 if( corpse_name.empty() ) {
9938 return std::string();
9939 }
9940 return corpse_name;
9941}
std::string corpse_name
Definition: item.h:2177

References corpse_name.

◆ get_coverage()

int item::get_coverage ( ) const

Returns the relative coverage that this item has when worn.

Values range from 0 (not covering anything, or no armor at all) to 100 (covering the whole body part). Items that cover more are more likely to absorb damage from attacks.

Definition at line 5908 of file item.cpp.

5909{
5910 const islot_armor *t = find_armor_data();
5911 if( t == nullptr ) {
5912 return 0;
5913 }
5914 return t->coverage;
5915}
int coverage
Percentage of the body part area that this item covers.
Definition: itype.h:255

References islot_armor::coverage, and find_armor_data().

Referenced by Character::armor_absorb(), armor_info(), armor_inventory_preset::armor_inventory_preset(), Character::block_ranged_hit(), relic_funcs::check_recharge_reqs(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), clothing_mod::get_mod_val(), character_funcs::is_bp_immune_to(), map::player_in_field(), tutorial_game::post_action(), wind_resistance_from_item_list(), and mdefense::zapback().

◆ get_covered_body_parts() [1/2]

body_part_set item::get_covered_body_parts ( ) const

Bitset of all covered body parts.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Definition at line 756 of file item.cpp.

757{
759}

References get_covered_body_parts(), and get_side().

Referenced by npc::adjust_worn(), Character::armor_absorb(), armor_info(), Character::can_swap(), Character::can_wear(), covers(), get_covered_body_parts(), layer_item(), on_wear(), player_morale::on_worn_item_washed(), player_morale::set_worn(), and weather_effect::wet_player().

◆ get_covered_body_parts() [2/2]

body_part_set item::get_covered_body_parts ( side  s) const

Bitset of all covered body parts, from a specific side.

If the bit is set, the body part is covered by this item (when worn). The index of the bit should be a body part, for example:

if( some_armor.get_covered_body_parts().test( bp_head ) ) { ... }

For testing only a single body part, use covers instead. This function allows you to get the whole covering data in one call.

Parameters
sSpecifies the side. Will be ignored for non-sided items.

Definition at line 761 of file item.cpp.

762{
763 body_part_set res;
764
765 if( is_gun() ) {
766 // Currently only used for guns with the should strap mod, other guns might
767 // go on another bodypart.
768 res.set( bp_torso );
769 }
770
771 const islot_armor *armor = find_armor_data();
772 if( armor == nullptr ) {
773 return res;
774 }
775
776 res |= armor->covers;
777
778 if( !armor->sided ) {
779 return res; // Just ignore the side.
780 }
781
782 switch( s ) {
783 case side::BOTH:
784 case side::num_sides:
785 break;
786
787 case side::LEFT:
788 res.reset( bp_arm_r );
789 res.reset( bp_hand_r );
790 res.reset( bp_leg_r );
791 res.reset( bp_foot_r );
792 break;
793
794 case side::RIGHT:
795 res.reset( bp_arm_l );
796 res.reset( bp_hand_l );
797 res.reset( bp_leg_l );
798 res.reset( bp_foot_l );
799 break;
800 }
801
802 return res;
803}
void set(const body_part &bp)
Definition: bodypart.h:253
void reset()
Definition: bodypart.h:256
bool sided
Whether this item can be worn on either side of the body.
Definition: itype.h:242
body_part_set covers
Bitfield of enum body_part TODO: document me.
Definition: itype.h:238

References BOTH, bp_arm_l, bp_arm_r, bp_foot_l, bp_foot_r, bp_hand_l, bp_hand_r, bp_leg_l, bp_leg_r, bp_torso, islot_armor::covers, find_armor_data(), is_gun(), LEFT, num_sides, body_part_set::reset(), RIGHT, body_part_set::set(), and islot_armor::sided.

◆ get_enchantments()

const std::vector< enchantment > & item::get_enchantments ( ) const

Definition at line 6986 of file item.cpp.

6987{
6988 if( !is_relic() ) {
6989 static const std::vector<enchantment> fallback;
6990 return fallback;
6991 }
6992 return relic_data->get_enchantments();
6993}
bool is_relic() const
Definition: item.cpp:6981

References is_relic(), and relic_data.

Referenced by bonus_from_enchantments(), bonus_from_enchantments_wielded(), process_relic(), and Character::recalculate_enchantment_cache().

◆ get_encumber()

int item::get_encumber ( const Character p) const

Returns the encumbrance value that this item has when worn by given player.

Returns 0 if this is can not be worn at all.

Definition at line 5800 of file item.cpp.

5801{
5802
5803 units::volume contents_volume( 0_ml );
5804
5805 contents_volume += contents.item_size_modifier();
5806
5807 if( p.is_worn( *this ) ) {
5808 const islot_armor *t = find_armor_data();
5809
5810 if( t != nullptr && t->max_encumber != 0 ) {
5811 units::volume char_storage( 0_ml );
5812
5813 for( const item &e : p.worn ) {
5814 char_storage += e.get_storage();
5815 }
5816
5817 if( char_storage != 0_ml ) {
5818 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5819 contents_volume += units::from_milliliter( static_cast<int64_t>( t->storage.value() ) *
5820 p.inv.volume().value() / char_storage.value() );
5821 }
5822 }
5823 }
5824
5825 return get_encumber_when_containing( p, contents_volume );
5826}
inventory inv
Definition: character.h:1581
std::list< item > worn
Definition: character.h:1569
bool is_worn(const item &thing) const
Definition: character.h:1099
units::volume volume() const
Definition: inventory.cpp:1060
units::volume item_size_modifier() const
constexpr quantity< value_type, volume_in_milliliter_tag > from_milliliter(const value_type v)
Definition: units_volume.h:25
int max_encumber
When storage is full, how much it encumbers the player.
Definition: itype.h:250
units::volume storage
How much storage this items provides when worn.
Definition: itype.h:275

References contents, find_armor_data(), units::from_milliliter(), get_encumber_when_containing(), get_storage(), Character::inv, Character::is_worn(), item_contents::item_size_modifier(), islot_armor::max_encumber, islot_armor::storage, units::quantity< V, U >::value(), inventory::volume(), and Character::worn.

Referenced by armor_fit_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), repair_item_actor::can_repair_target(), Character::can_wear(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), repair_item_actor::default_action(), Character::head_cloth_encumbrance(), Character::item_wear_cost(), layer_item(), tname(), and sew_advanced_actor::use().

◆ get_encumber_when_containing()

int item::get_encumber_when_containing ( const Character p,
const units::volume contents_volume 
) const

Returns the encumbrance value that this item has when worn by given player, when containing a particular volume of contents.

Returns 0 if this can not be worn at all.

Definition at line 5828 of file item.cpp.

5830{
5831 const islot_armor *t = find_armor_data();
5832 if( t == nullptr ) {
5833 // handle wearable guns (e.g. shoulder strap) as special case
5834 return is_gun() ? volume() / 750_ml : 0;
5835 }
5836 int encumber = t->encumber;
5837
5838 // Non-rigid items add additional encumbrance proportional to their volume
5839 if( !type->rigid ) {
5840 const int capacity = get_total_capacity().value();
5841
5842 if( t->max_encumber != 0 ) {
5843
5844 if( capacity > 0 ) {
5845 // Cast up to 64 to prevent overflow. Dividing before would prevent this but lose data.
5846 encumber += static_cast<int64_t>( t->max_encumber - t->encumber ) * contents_volume.value() /
5847 capacity;
5848 } else {
5849 debugmsg( "Non-rigid item (%s) without storage capacity.", tname() );
5850 }
5851 } else {
5852 encumber += contents_volume / 500_ml;
5853 }
5854 }
5855
5856 // Fit checked before changes, fitting shouldn't reduce penalties from patching.
5857 if( has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
5858 encumber = std::max( encumber / 2, encumber - 10 );
5859 }
5860
5861 // TODO: Should probably have sizing affect coverage
5862 const sizing sizing_level = get_sizing( p, encumber != 0 );
5863 switch( sizing_level ) {
5866 // non small characters have a HARD time wearing undersized clothing
5867 encumber *= 3;
5868 break;
5871 // clothes bag up around smol characters and encumber them more
5872 encumber *= 2;
5873 break;
5874 default:
5875 break;
5876 }
5877
5878 encumber += static_cast<int>( std::ceil( get_clothing_mod_val( clothing_mod_type_encumbrance ) ) );
5879
5880 return encumber;
5881}
@ clothing_mod_type_encumbrance
Definition: clothing_mod.h:22
int encumber
How much this item encumbers the player.
Definition: itype.h:246

References big_sized_small_char, clothing_mod_type_encumbrance, debugmsg, islot_armor::encumber, find_armor_data(), flag_FIT(), flag_VARSIZE(), get_clothing_mod_val(), get_sizing(), get_total_capacity(), has_flag(), human_sized_small_char, is_gun(), islot_armor::max_encumber, itype::rigid, small_sized_big_char, small_sized_human_char, tname(), type, units::quantity< V, U >::value(), and volume().

Referenced by armor_info(), and get_encumber().

◆ get_env_resist()

int item::get_env_resist ( int  override_base_resist = 0) const

Returns the resistance to environmental effects (islot_armor::env_resist) that this item provides when worn.

See player::get_env_resist. Higher values are better. For non-armor it returns 0.

Parameters
override_base_resistPass this to artifically increase the base resistance, so that the function can take care of other modifications to resistance for you. Note that this parameter will never decrease base resistnace.

Definition at line 5771 of file item.cpp.

5772{
5773 const islot_armor *t = find_armor_data();
5774 if( t == nullptr ) {
5775 return is_pet_armor() ? type->pet_armor->env_resist : 0;
5776 }
5777 // modify if item is a gas mask and has filter
5778 int resist_base = t->env_resist;
5779 int resist_filter = get_var( "overwrite_env_resist", 0 );
5780 int resist = std::max( { resist_base, resist_filter, override_base_resist } );
5781
5782 return std::lround( resist * get_relative_health() );
5783}
float get_relative_health() const
Relative item health.
Definition: item.cpp:6229
int env_resist
Resistance to environmental effects.
Definition: itype.h:263

References islot_armor::env_resist, find_armor_data(), get_relative_health(), get_var(), is_pet_armor(), itype::pet_armor, and type.

Referenced by acid_resist(), armor_inventory_preset::armor_inventory_preset(), armor_protection_info(), anonymous_namespace{armor_layers.cpp}::clothing_protection(), fire_resist(), and tutorial_game::post_action().

◆ get_explosion_data()

struct fuel_explosion item::get_explosion_data ( )

Definition at line 6839 of file item.cpp.

6840{
6841 static struct fuel_explosion null_data;
6842 return has_explosion_data() ? type->fuel->explosion_data : null_data;
6843}
bool has_explosion_data() const
Definition: item.cpp:6834

References type.

Referenced by vehicle::explode_fuel().

◆ get_flags()

const item::FlagsSetType & item::get_flags ( ) const

returs read-only set of flags of this item (not including flags from item type or gunmods)

Definition at line 5361 of file item.cpp.

5362{
5363 return item_tags;
5364}

References item_tags.

Referenced by final_info().

◆ get_food() [1/2]

item * item::get_food ( )

Definition at line 6650 of file item.cpp.

6651{
6652 return get_food_impl( this );
6653}
static Item * get_food_impl(Item *it)
Definition: item.cpp:6639

References get_food_impl().

Referenced by basic_info(), color_in_inventory(), npc::consume_food(), npc::decide_needs(), zone_manager::get_near_zone_type_for_item(), and info().

◆ get_food() [2/2]

const item * item::get_food ( ) const

Definition at line 6655 of file item.cpp.

6656{
6657 return get_food_impl( this );
6658}

References get_food_impl().

◆ get_free_mod_locations()

int item::get_free_mod_locations ( const gunmod_location location) const

Number of mods that can still be installed into the given mod location, for non-guns it always returns 0.

Definition at line 4098 of file item.cpp.

4099{
4100 if( !is_gun() ) {
4101 return 0;
4102 }
4103
4104 std::map<gunmod_location, int> mod_locations = get_mod_locations();
4105
4106 const auto loc = mod_locations.find( location );
4107 if( loc == mod_locations.end() ) {
4108 return 0;
4109 }
4110 int result = loc->second;
4111 for( const item *elem : contents.all_items_top() ) {
4112 const cata::value_ptr<islot_gunmod> &mod = elem->type->gunmod;
4113 if( mod && mod->location == location ) {
4114 result--;
4115 }
4116 }
4117 return result;
4118}
This class is essentially a copyable unique pointer.
Definition: value_ptr.h:19
std::map< gunmod_location, int > get_mod_locations() const
Get mod locations, including those added by other mods.
Definition: item.cpp:4081

References item_contents::all_items_top(), contents, get_mod_locations(), and is_gun().

Referenced by saw_stock_actor::can_use_on(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_gun_ups_drain()

int item::get_gun_ups_drain ( ) const

Definition at line 9953 of file item.cpp.

9954{
9955 int draincount = 0;
9956 if( type->gun ) {
9957 int modifier = 0;
9958 float multiplier = 1.0f;
9959 for( const item *mod : gunmods() ) {
9960 modifier += mod->type->gunmod->ups_charges_modifier;
9961 multiplier *= mod->type->gunmod->ups_charges_multiplier;
9962 }
9963 draincount = ( type->gun->ups_charges * multiplier ) + modifier;
9964 }
9965 return draincount;
9966}

References itype::gun, gunmods(), and type.

Referenced by character_funcs::ammo_count_for(), npc::decide_needs(), ranged::fire_gun(), ranged::gunmode_checks_weapon(), turret_data::query(), item_funcs::shots_remaining(), and target_ui::update_ammo_range_from_gun_mode().

◆ get_layer()

layer_level item::get_layer ( ) const

Returns clothing layer for item.

Definition at line 5883 of file item.cpp.

5884{
5885 if( type->armor ) {
5886 // We assume that an item will never have per-item flags defining its
5887 // layer, so we can defer to the itype.
5888 return type->layer;
5889 }
5890
5891 if( has_flag( flag_PERSONAL ) ) {
5892 return PERSONAL_LAYER;
5893 } else if( has_flag( flag_SKINTIGHT ) ) {
5894 return UNDERWEAR_LAYER;
5895 } else if( has_flag( flag_WAIST ) ) {
5896 return WAIST_LAYER;
5897 } else if( has_flag( flag_OUTER ) ) {
5898 return OUTER_LAYER;
5899 } else if( has_flag( flag_BELTED ) ) {
5900 return BELTED_LAYER;
5901 } else if( has_flag( flag_AURA ) ) {
5902 return AURA_LAYER;
5903 } else {
5904 return REGULAR_LAYER;
5905 }
5906}
@ WAIST_LAYER
Definition: enums.h:222
@ UNDERWEAR_LAYER
Definition: enums.h:218
@ REGULAR_LAYER
Definition: enums.h:220
@ BELTED_LAYER
Definition: enums.h:226
@ PERSONAL_LAYER
Definition: enums.h:216
@ AURA_LAYER
Definition: enums.h:228
@ OUTER_LAYER
Definition: enums.h:224
layer_level layer
Definition: itype.h:1028

References itype::armor, AURA_LAYER, BELTED_LAYER, flag_AURA(), flag_BELTED(), flag_OUTER(), flag_PERSONAL(), flag_SKINTIGHT(), flag_WAIST(), has_flag(), itype::layer, OUTER_LAYER, PERSONAL_LAYER, REGULAR_LAYER, type, UNDERWEAR_LAYER, and WAIST_LAYER.

Referenced by Character::item_wear_cost(), profession::items(), and layer_item().

◆ get_making()

const recipe & item::get_making ( ) const

Get the stored recipe for in progress crafts.

Causes a debugmsg if called on a non-craft and returns the null recipe.

Returns
the recipe in progress

Definition at line 10110 of file item.cpp.

10111{
10112 if( !craft_data_ ) {
10113 debugmsg( "'%s' is not a craft or has a null recipe", tname() );
10114 static const recipe dummy{};
10115 return dummy;
10116 }
10117 assert( craft_data_->making );
10118 return *craft_data_->making;
10119}

References craft_data_, debugmsg, and tname().

Referenced by iuse::craft(), handle_craft_failure(), and set_next_failure_point().

◆ get_min_str()

int item::get_min_str ( ) const

Definition at line 10065 of file item.cpp.

10066{
10067 if( type->gun ) {
10068 int min_str = type->min_str;
10069 for( const item *mod : gunmods() ) {
10070 min_str += mod->type->gunmod->min_str_required_mod;
10071 }
10072 return min_str > 0 ? min_str : 0;
10073 } else {
10074 return type->min_str;
10075 }
10076}
int min_str
Definition: itype.h:937

References itype::gun, gunmods(), itype::min_str, and type.

Referenced by basic_info(), Character::enumerate_unmet_requirements(), ranged::get_str_draw_penalty(), aim_activity_actor::load_RAS_weapon(), Character::meets_stat_requirements(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), and ranged::str_draw_range_modifier().

◆ get_mod_locations()

std::map< gunmod_location, int > item::get_mod_locations ( ) const

Get mod locations, including those added by other mods.

Definition at line 4081 of file item.cpp.

4082{
4083 std::map<gunmod_location, int> mod_locations = type->gun->valid_mod_locations;
4084
4085 for( const item *mod : gunmods() ) {
4086 if( !mod->type->gunmod->add_mod.empty() ) {
4087 std::map<gunmod_location, int> add_locations = mod->type->gunmod->add_mod;
4088
4089 for( const std::pair<const gunmod_location, int> &add_location : add_locations ) {
4090 mod_locations[add_location.first] += add_location.second;
4091 }
4092 }
4093 }
4094
4095 return mod_locations;
4096}

References itype::gun, gunmods(), and type.

Referenced by get_free_mod_locations(), gun_info(), avatar_funcs::gunmod_remove(), and is_gunmod_compatible().

◆ get_mtype()

const mtype * item::get_mtype ( ) const
Returns
The monster type associated with this item (corpse). It is usually the type that this item is made of (e.g. corpse, meat or blood of the monster). May return a null-pointer.

Definition at line 6633 of file item.cpp.

6634{
6635 return corpse;
6636}

References corpse.

Referenced by computer_session::action_blood_anal(), burn(), activity_handlers::butcher_finish(), butcher_time_to_cut(), butchery_drops_harvest(), butchery_quarter(), consider_butchery(), editmap::draw_main_ui_overlay(), and game::revive_corpse().

◆ get_next_failure_point()

int item::get_next_failure_point ( ) const

Get the failure point stored in this item.

returns INT_MAX if the failure point is unset. Causes a debugmsg and returns INT_MAX if called on a non-craft.

Returns
an integer >= 0 representing a percent to 5 decimal places. 67.32 percent would be represented as 6732000

Definition at line 895 of file crafting.cpp.

896{
897 if( !is_craft() ) {
898 debugmsg( "get_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
899 return INT_MAX;
900 }
901 return craft_data_->next_failure_point >= 0 ? craft_data_->next_failure_point : INT_MAX;
902}

References craft_data_, debugmsg, is_craft(), and tname().

◆ get_old_owner()

faction_id item::get_old_owner ( ) const

Definition at line 1288 of file item.cpp.

1289{
1291 return old_owner;
1292}
faction_id old_owner
Definition: item.h:2235
void validate_ownership() const
Definition: item.cpp:1294

References old_owner, and validate_ownership().

Referenced by is_old_owner().

◆ get_owner()

faction_id item::get_owner ( ) const

Definition at line 1282 of file item.cpp.

1283{
1285 return owner;
1286}

References owner, and validate_ownership().

Referenced by get_owner_name(), handle_pickup_ownership(), is_owned_by(), and query_consume_ownership().

◆ get_owner_name()

std::string item::get_owner_name ( ) const

Definition at line 1264 of file item.cpp.

1265{
1266 if( !g->faction_manager_ptr->get( get_owner() ) ) {
1267 debugmsg( "item::get_owner_name() item %s has no valid nor null faction id ", tname() );
1268 return "no owner";
1269 }
1270 return g->faction_manager_ptr->get( get_owner() )->name;
1271}
faction_id get_owner() const
Definition: item.cpp:1282

References debugmsg, g, get_owner(), and tname().

Referenced by basic_info().

◆ get_pet_armor_bodytype()

std::string item::get_pet_armor_bodytype ( ) const

Definition at line 5949 of file item.cpp.

5950{
5951 return is_pet_armor() ? type->pet_armor->bodytype : "";
5952}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_max_vol()

units::volume item::get_pet_armor_max_vol ( ) const

Definition at line 5939 of file item.cpp.

5940{
5941 return is_pet_armor() ? type->pet_armor->max_vol : 0_ml;
5942}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_pet_armor_min_vol()

units::volume item::get_pet_armor_min_vol ( ) const

Definition at line 5944 of file item.cpp.

5945{
5946 return is_pet_armor() ? type->pet_armor->min_vol : 0_ml;
5947}

References is_pet_armor(), itype::pet_armor, and type.

◆ get_plant_epoch()

time_duration item::get_plant_epoch ( ) const

Time it takes to grow from one stage to another.

There are 4 plant stages: seed, seedling, mature and harvest. Non-seed items return 0.

Definition at line 9800 of file item.cpp.

9801{
9802 if( !type->seed ) {
9803 return 0_turns;
9804 }
9805 // Growing times have been based around real world season length rather than
9806 // the default in-game season length to give
9807 // more accuracy for longer season lengths
9808 // Also note that seed->grow is the time it takes from seeding to harvest, this is
9809 // divided by 3 to get the time it takes from one plant state to the next.
9810 // TODO: move this into the islot_seed
9811 return type->seed->grow * calendar::season_ratio() / 3;
9812}
float season_ratio()
Definition: calendar.cpp:485
cata::value_ptr< islot_seed > seed
Definition: itype.h:865

References calendar::season_ratio(), itype::seed, and type.

◆ get_plant_name()

std::string item::get_plant_name ( ) const

The name of the plant as it appears in the various informational menus.

This should be translated. Returns an empty string for non-seed items.

Definition at line 9814 of file item.cpp.

9815{
9816 if( !type->seed ) {
9817 return std::string{};
9818 }
9819 return type->seed->plant_name.translated();
9820}

References itype::seed, and type.

Referenced by map::rotten_item_spawn().

◆ get_property_int64_t()

int64_t item::get_property_int64_t ( const std::string &  prop,
int64_t  def = 0 
) const

Definition at line 5377 of file item.cpp.

5378{
5379 const auto it = type->properties.find( prop );
5380 if( it != type->properties.end() ) {
5381 char *e = nullptr;
5382 int64_t r = std::strtoll( it->second.c_str(), &e, 10 );
5383 if( !it->second.empty() && *e == '\0' ) {
5384 return r;
5385 }
5386 debugmsg( "invalid property '%s' for item '%s'", prop.c_str(), tname() );
5387 }
5388 return def;
5389}
std::map< std::string, std::string > properties
Definition: itype.h:915

References debugmsg, itype::properties, tname(), and type.

Referenced by ranged::throw_item().

◆ get_property_string()

std::string item::get_property_string ( const std::string &  prop,
const std::string &  def = "" 
) const

Get typed property for item.

Return same type as the passed default value, or string where no default provided

Definition at line 5371 of file item.cpp.

5372{
5373 const auto it = type->properties.find( prop );
5374 return it != type->properties.end() ? it->second : def;
5375}

References itype::properties, and type.

Referenced by iuse::capture_monster_act().

◆ get_qualities()

std::map< quality_id, int > item::get_qualities ( ) const

Definition at line 5438 of file item.cpp.

5439{
5440 std::map<quality_id, int> qualities;
5441 for( const auto &quality : type->qualities ) {
5442 qualities[quality.first] = get_quality( quality.first );
5443 }
5444 return qualities;
5445}
int get_quality(const quality_id &id) const
Definition: item.cpp:5391
std::map< quality_id, int > qualities
Definition: itype.h:914

References get_quality(), itype::qualities, and type.

Referenced by inventory::update_quality_cache().

◆ get_quality()

int item::get_quality ( const quality_id id) const

EXCEPTION: Items with quality BOIL only count as such if they are empty, excluding items of their ammo type if they are tools.

Definition at line 5391 of file item.cpp.

5392{
5393 int return_quality = INT_MIN;
5394
5395 /**
5396 * EXCEPTION: Items with quality BOIL only count as such if they are empty,
5397 * excluding items of their ammo type if they are tools.
5398 */
5399 auto block_boil_filter = [this]( const item & itm ) {
5400 // We want to skip (do not block) only those : correct ammo, correct magazine, correct toolmod.Everything else should block.
5401 if( &itm == this ) {
5402 // Do not block if checking itself - we are checking only item contents not item itself.
5403 return false;
5404 } else if( itm.is_ammo() ) {
5405 return ammo_types().count( itm.ammo_type() ) == 0;
5406 } else if( itm.is_magazine() ) {
5407 // we want to return "fine for boiling" if any of the ammo types match and "blocks boiling" if none match.
5408 for( const ammotype &at : ammo_types() ) {
5409 for( const ammotype &mag_at : itm.ammo_types() ) {
5410 if( at == mag_at ) {
5411 return false;
5412 }
5413 }
5414 }
5415 return true;
5416 } else if( itm.is_toolmod() ) {
5417 return false;
5418 }
5419 return true;
5420 };
5421 // if it's has boil quality and it's empty, it's good to boil. If it's not empty and it's not a tool (it's probably a container), it's not good to boil. If it's a tool, it gets an extra chance: if it's only contents are mods or batteries, it's still good.
5422 // Also we are using inverted filter, since we don't care about items that the filter likes, we only care if it find something it doesn't like.
5423 if( id == quality_id( "BOIL" ) && !contents.empty() &&
5424 ( !is_tool() || has_item_with( block_boil_filter ) ) ) {
5425 return INT_MIN;
5426 }
5427
5428 for( const std::pair<const quality_id, int> &quality : type->qualities ) {
5429 if( quality.first == id ) {
5430 return_quality = quality.second;
5431 }
5432 }
5433 return_quality = std::max( return_quality, contents.best_quality( id ) );
5434
5435 return return_quality;
5436}
int best_quality(const quality_id &id) const
string_id< quality > quality_id
Definition: type_id.h:184

References ammo_types(), item_contents::best_quality(), contents, item_contents::empty(), visitable< item >::has_item_with(), is_tool(), itype::qualities, and type.

Referenced by iuse::clear_rubble(), iuse::crowbar(), dig_pit_moves_and_byproducts(), get_qualities(), bionic::get_quality(), has_quality_internal(), Character::item_with_best_of_quality(), activity_handlers::lockpicking_finish(), max_quality_internal(), and pick_lock_actor::use().

◆ get_random_material()

const material_type & item::get_random_material ( ) const

Get a material reference to a random material that this item is made of.

This might return the null-material, you may check this with material_type::ident. Note that this may also return a different material each time it's invoked (if the item is made from several materials).

Definition at line 7154 of file item.cpp.

7155{
7156 return random_entry( made_of(), material_id::NULL_ID() ).obj();
7157}
V random_entry(const C &container, D default_value)
Returns a random entry in the container.
Definition: rng.h:88

References made_of(), string_id< material_type >::NULL_ID(), and random_entry().

Referenced by Character::armor_absorb().

◆ get_relative_health()

float item::get_relative_health ( ) const

Relative item health.

Returns 1 for undamaged ||items, values in the range (0, 1) for damaged items and values above 1 for reinforced ++items.

Definition at line 6229 of file item.cpp.

6230{
6231 return ( max_damage() + 1.0f - damage() ) / ( max_damage() + 1.0f );
6232}

References damage(), and max_damage().

Referenced by get_base_env_resist(), and get_env_resist().

◆ get_relative_rot()

double item::get_relative_rot ( ) const

Get rot value relative to shelf life (or 0 if item does not spoil)

Definition at line 5539 of file item.cpp.

5540{
5541 if( goes_bad() ) {
5542 return rot / get_shelf_life();
5543 }
5544 return 0;
5545}
Definition: rot.cpp:11

References get_shelf_life(), and goes_bad().

Referenced by calc_rot(), Character::consume_effects(), fill_with(), Character::fun_for(), comestible_inventory_preset::get_freshness(), get_freshness_description(), get_most_rotten_component(), comestible_inventory_preset::get_time_left(), has_rotten_away(), item(), and rate_food().

◆ get_relic_recharge_scheme()

const std::vector< relic_recharge > & item::get_relic_recharge_scheme ( ) const

Definition at line 7033 of file item.cpp.

7034{
7035 return relic_data->get_recharge_scheme();
7036}

References relic_data.

Referenced by relic_funcs::process_recharge().

◆ get_reload_time()

int item::get_reload_time ( ) const

Returns the reload time of the gun.

Returns 0 if not a gun.

Definition at line 6536 of file item.cpp.

6537{
6538 if( !is_gun() && !is_magazine() ) {
6539 return 0;
6540 }
6541
6542 int reload_time = is_gun() ? type->gun->reload_time : type->magazine->reload_time;
6543 for( const item *mod : gunmods() ) {
6544 reload_time = static_cast<int>( reload_time * ( 100 + mod->type->gunmod->reload_modifier ) / 100 );
6545 }
6546
6547 return reload_time;
6548}

References itype::gun, gunmods(), is_gun(), is_magazine(), itype::magazine, and type.

Referenced by ideal_ranged_dps(), Character::item_reload_cost(), and item_reload_option::moves().

◆ get_remaining_capacity_for_liquid() [1/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
bool  allow_bucket = false,
std::string *  err = nullptr 
) const

How much more of this liquid (in charges) can be put in this container.

If this is not a container (or not suitable for the liquid), it returns 0. Note that mixing different types of liquid is not possible. Also note that this works for guns and tools that accept liquid ammo.

Parameters
liquidLiquid to check capacity for
allow_bucketAllow filling non-sealable containers
errMessage to print if no more material will fit

Definition at line 8438 of file item.cpp.

8440{
8441 const auto error = [ &err ]( const std::string & message ) {
8442 if( err != nullptr ) {
8443 *err = message;
8444 }
8445 return 0;
8446 };
8447
8448 int remaining_capacity = 0;
8449
8450 // TODO: (sm) is_reloadable_with and this function call each other and can recurse for
8451 // watertight containers.
8452 if( !is_container() && is_reloadable_with( liquid.typeId() ) ) {
8453 if( ammo_remaining() != 0 && ammo_current() != liquid.typeId() ) {
8454 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8455 }
8456 remaining_capacity = ammo_capacity() - ammo_remaining();
8457 } else if( is_container() ) {
8458 if( !type->container->watertight ) {
8459 return error( string_format( _( "That %s isn't water-tight." ), tname() ) );
8460 } else if( !type->container->seals && ( !allow_bucket || !is_bucket() ) ) {
8461 return error( string_format( is_bucket() ?
8462 _( "That %s must be on the ground or held to hold contents!" )
8463 : _( "You can't seal that %s!" ), tname() ) );
8464 } else if( !contents.empty() && contents.front().typeId() != liquid.typeId() ) {
8465 return error( string_format( _( "You can't mix loads in your %s." ), tname() ) );
8466 }
8467 remaining_capacity = liquid.charges_per_volume( get_container_capacity() );
8468 if( !contents.empty() ) {
8469 remaining_capacity -= contents.front().charges;
8470 }
8471 } else {
8472 return error( string_format( _( "That %1$s won't hold %2$s." ), tname(),
8473 liquid.tname() ) );
8474 }
8475
8476 if( remaining_capacity <= 0 ) {
8477 return error( string_format( _( "Your %1$s can't hold any more %2$s." ), tname(),
8478 liquid.tname() ) );
8479 }
8480
8481 return remaining_capacity;
8482}
std::string message
Definition: mapgen.cpp:411

References _, ammo_capacity(), ammo_current(), ammo_remaining(), charges, charges_per_volume(), itype::container, contents, item_contents::empty(), detail::digits::error, item_contents::front(), get_container_capacity(), is_bucket(), is_container(), is_reloadable_with(), mapgen_defer::message, string_format(), tname(), type, and typeId().

Referenced by add_rain_to_container(), fill_with(), get_remaining_capacity_for_liquid(), is_container_full(), maple_tree_sap_container(), advanced_inventory::move_content(), Character::pour_into(), item_reload_option::qty(), and reload().

◆ get_remaining_capacity_for_liquid() [2/2]

int item::get_remaining_capacity_for_liquid ( const item liquid,
const Character p,
std::string *  err = nullptr 
) const

Definition at line 8484 of file item.cpp.

8486{
8487 const bool allow_bucket = p.is_wielding( *this ) || !p.has_item( *this );
8488 int res = get_remaining_capacity_for_liquid( liquid, allow_bucket, err );
8489
8490 if( res > 0 && !type->rigid && p.inv.has_item( *this ) ) {
8491 const units::volume volume_to_expand = std::max( p.volume_capacity() - p.volume_carried(),
8492 0_ml );
8493
8494 res = std::min( liquid.charges_per_volume( volume_to_expand ), res );
8495
8496 if( res == 0 && err != nullptr ) {
8497 *err = string_format( _( "That %s doesn't have room to expand." ), tname() );
8498 }
8499 }
8500
8501 return res;
8502}
units::volume volume_capacity() const
Definition: character.cpp:2668
bool is_wielding(const item &target) const
Definition: character.cpp:3231
units::volume volume_carried() const
Definition: character.cpp:2540

References _, charges_per_volume(), get_remaining_capacity_for_liquid(), visitable< T >::has_item(), Character::inv, Character::is_wielding(), itype::rigid, string_format(), tname(), type, Character::volume_capacity(), and Character::volume_carried().

◆ get_remaining_chapters()

int item::get_remaining_chapters ( const Character ch) const

Get the number of unread chapters.

If the item is no book or has no chapters, it returns 0. This is a per-character setting, different characters may have different number of unread chapters.

Definition at line 7105 of file item.cpp.

7106{
7107 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7108 return get_var( var, get_chapters() );
7109}

References get_chapters(), character_id::get_value(), get_var(), Character::getID(), and string_format().

Referenced by book_info(), display_name(), character_funcs::get_book_fun_for(), and mark_chapter_as_read().

◆ get_rot()

time_duration item::get_rot ( ) const
inline

Definition at line 861 of file item.h.

861 {
862 return rot;
863 }

Referenced by butchery_drops_harvest(), and has_rotten_away().

◆ get_safe_reference()

safe_reference< item > item::get_safe_reference ( )

Return a pointer-like type that's automatically invalidated if this item is destroyed or assigned-to.

Definition at line 449 of file item.cpp.

450{
451 return anchor.reference_to( this );
452}
safe_reference_anchor anchor
Definition: item.h:2173
safe_reference< T > reference_to(T *object)

References anchor, and safe_reference_anchor::reference_to().

Referenced by active_item_cache::add(), and explosion_handler::ExplosionProcess::move_entity().

◆ get_shelf_life()

time_duration item::get_shelf_life ( ) const

Get the shelf life of the item.

Definition at line 5527 of file item.cpp.

5528{
5529 if( goes_bad() ) {
5530 if( is_food() ) {
5531 return get_comestible()->spoils;
5532 } else if( is_corpse() ) {
5533 return 24_hours;
5534 }
5535 }
5536 return 0_turns;
5537}

References get_comestible(), goes_bad(), is_corpse(), and is_food().

Referenced by basic_info(), calc_rot(), food_info(), get_freshness_description(), get_relative_rot(), process_corpse(), set_relative_rot(), spoilage_sort_order(), and stacks_with().

◆ get_side()

side item::get_side ( ) const

Returns side item currently worn on.

Returns BOTH if item is not sided or no side currently set

Definition at line 811 of file item.cpp.

812{
813 // MSVC complains if directly cast double to enum
814 return static_cast<side>( static_cast<int>( get_var( "lateral",
815 static_cast<int>( side::BOTH ) ) ) );
816}
side
Definition: bodypart.h:67

References BOTH, and get_var().

Referenced by display_name(), get_covered_body_parts(), on_wear(), and swap_side().

◆ get_sizing()

item::sizing item::get_sizing ( const Character p,
bool  wearable 
) const

Definition at line 1180 of file item.cpp.

1181{
1182 if( wearable ) {
1183 const bool small = p.get_size() == MS_TINY;
1184 const bool big = p.get_size() == MS_HUGE;
1185
1186 // due to the iterative nature of these features, something can fit and be undersized/oversized
1187 // but that is fine because we have separate logic to adjust encumberance per each. One day we
1188 // may want to have fit be a flag that only applies if a piece of clothing is sized for you as there
1189 // is a bit of cognitive dissonance when something 'fits' and is 'oversized' and the same time
1190 const bool undersize = has_flag( flag_UNDERSIZE );
1191 const bool oversize = has_flag( flag_OVERSIZE );
1192
1193 if( undersize ) {
1194 if( small ) {
1196 } else if( big ) {
1198 } else {
1200 }
1201 } else if( oversize ) {
1202 if( big ) {
1204 } else if( small ) {
1206 } else {
1208 }
1209 } else {
1210 if( big ) {
1212 } else if( small ) {
1214 } else {
1216 }
1217 }
1218 }
1219 return sizing::not_wearable;
1220
1221}
m_size get_size() const override
Get size class of character.
Definition: character.cpp:573
@ MS_TINY
Definition: creature.h:58
@ MS_HUGE
Definition: creature.h:62
static const std::string flag_UNDERSIZE("UNDERSIZE")
static const std::string flag_OVERSIZE("OVERSIZE")

References big_sized_big_char, big_sized_human_char, big_sized_small_char, flag_OVERSIZE(), flag_UNDERSIZE(), Character::get_size(), has_flag(), human_sized_big_char, human_sized_human_char, human_sized_small_char, MS_HUGE, MS_TINY, not_wearable, small_sized_big_char, small_sized_human_char, and small_sized_small_char.

Referenced by armor_fit_info(), armor_info(), get_encumber_when_containing(), and tname().

◆ get_storage()

units::volume item::get_storage ( ) const

Returns the storage amount (islot_armor::storage) that this item provides when worn.

For non-armor it returns 0. The storage amount increases the volume capacity of the character that wears the item.

Definition at line 5740 of file item.cpp.

5741{
5742 const islot_armor *t = find_armor_data();
5743 if( t == nullptr ) {
5744 return is_pet_armor() ? type->pet_armor->storage : 0_ml;
5745 }
5746 units::volume storage = t->storage;
5748 storage += std::lround( mod ) * units::legacy_volume_factor;
5749
5750 return storage;
5751}
@ clothing_mod_type_storage
Definition: clothing_mod.h:24

References clothing_mod_type_storage, find_armor_data(), get_clothing_mod_val(), is_pet_armor(), units::legacy_volume_factor, itype::pet_armor, islot_armor::storage, and type.

Referenced by animal_armor_info(), armor_info(), armor_inventory_preset::armor_inventory_preset(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), get_encumber(), get_total_capacity(), monexamine::give_items_to(), pickup::obtain_and_tokenize_items(), om_carry_weight_to_trips(), tutorial_game::post_action(), pickup::reorder_for_dropping(), Character::takeoff(), and sew_advanced_actor::use().

◆ get_techniques()

std::set< matec_id > item::get_techniques ( ) const

Returns all the martial art techniques that this items supports.

Definition at line 5483 of file item.cpp.

5484{
5485 std::set<matec_id> result = type->techniques;
5486 result.insert( techniques.begin(), techniques.end() );
5487 return result;
5488}

References techniques, itype::techniques, and type.

Referenced by character_martial_arts::get_all_techniques().

◆ get_thickness()

int item::get_thickness ( ) const

Returns the islot_armor::thickness value, or 0 for non-armor.

Thickness is are relative value that affects the items resistance against bash / cutting / bullet damage.

Definition at line 5917 of file item.cpp.

5918{
5919 const islot_armor *t = find_armor_data();
5920 if( t == nullptr ) {
5921 return is_pet_armor() ? type->pet_armor->thickness : 0;
5922 }
5923 return t->thickness;
5924}
int thickness
TODO: document me.
Definition: itype.h:259

References find_armor_data(), is_pet_armor(), itype::pet_armor, islot_armor::thickness, and type.

Referenced by bash_resist(), bullet_resist(), cut_resist(), clothing_mod::get_mod_val(), and tutorial_game::post_action().

◆ get_total_capacity()

units::volume item::get_total_capacity ( ) const

It returns the maximum volume of any contents, including liquids, ammo, magazines, weapons, etc.

Definition at line 8417 of file item.cpp.

8418{
8420
8421 // Consider various iuse_actors which add containing capability
8422 // Treating these two as special cases for now; if more appear in the
8423 // future then this probably warrants a new method on use_function to
8424 // access this information generically.
8425 if( is_bandolier() ) {
8426 result += dynamic_cast<const bandolier_actor *>
8427 ( type->get_use( "bandolier" )->get_actor_ptr() )->max_stored_volume();
8428 }
8429
8430 if( is_holster() ) {
8431 result += dynamic_cast<const holster_actor *>
8432 ( type->get_use( "holster" )->get_actor_ptr() )->max_stored_volume();
8433 }
8434
8435 return result;
8436}
bool is_holster() const
Definition: item.cpp:6585

References use_function::get_actor_ptr(), get_container_capacity(), get_storage(), itype::get_use(), is_bandolier(), is_holster(), and type.

Referenced by armor_info(), and get_encumber_when_containing().

◆ get_uncraft_components()

std::vector< item_comp > item::get_uncraft_components ( ) const

Returns a list of components used to craft this item or the default components if it wasn't player-crafted.

Definition at line 10078 of file item.cpp.

10079{
10080 std::vector<item_comp> ret;
10081 if( components.empty() ) {
10082 //If item wasn't crafted with specific components use default recipe
10083 std::vector<std::vector<item_comp>> recipe = recipe_dictionary::get_uncraft(
10085 for( std::vector<item_comp> &component : recipe ) {
10086 ret.push_back( component.front() );
10087 }
10088 } else {
10089 //Make a new vector of components from the registered components
10090 for( const item &component : components ) {
10091 auto iter = std::find_if( ret.begin(), ret.end(), [component]( item_comp & obj ) {
10092 return obj.type == component.typeId();
10093 } );
10094
10095 if( iter != ret.end() ) {
10096 iter->count += component.count();
10097 } else {
10098 ret.push_back( item_comp( component.typeId(), component.count() ) );
10099 }
10100 }
10101 }
10102 return ret;
10103}

References components, component::count, recipe::disassembly_requirements(), requirement_data::get_components(), recipe_dictionary::get_uncraft(), cata::hash64_detail::ret, and typeId().

Referenced by disassemble_inventory_preset::disassemble_inventory_preset(), and stacks_with().

◆ get_usable_item()

item * item::get_usable_item ( const std::string &  use_name)

Checks this item and its contents (recursively) for types that have use_function with type use_name.

Returns the first item that does have such type or nullptr if none found.

Definition at line 7982 of file item.cpp.

7983{
7984 item *ret = nullptr;
7986 [&ret, &use_name]( item * it ) {
7987 if( it == nullptr ) {
7988 return VisitResponse::SKIP;
7989 }
7990 if( it->get_use_internal( use_name ) ) {
7991 ret = it;
7992 return VisitResponse::ABORT;
7993 }
7994 return VisitResponse::NEXT;
7995 } );
7996
7997 return ret;
7998}
const use_function * get_use_internal(const std::string &use_name) const
Definition: item.cpp:7974

References get_use_internal(), NEXT, cata::hash64_detail::ret, SKIP, and visitable< item >::visit_items().

Referenced by game::butcher(), activity_handlers::firstaid_finish(), Character::invoke_item(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), activity_handlers::repair_item_finish(), and activity_handlers::start_fire_finish().

◆ get_use()

const use_function * item::get_use ( const std::string &  use_name) const

Returns the pointer to use_function with name use_name assigned to the type of this item or any of its contents.

Checks contents recursively. Returns nullptr if not found.

Definition at line 7956 of file item.cpp.

7957{
7958 const use_function *fun = nullptr;
7960 [&fun, &use_name]( const item * it ) {
7961 if( it == nullptr ) {
7962 return VisitResponse::SKIP;
7963 }
7964 fun = it->get_use_internal( use_name );
7965 if( fun != nullptr ) {
7966 return VisitResponse::ABORT;
7967 }
7968 return VisitResponse::NEXT;
7969 } );
7970
7971 return fun;
7972}

References ABORT, get_use_internal(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by active_item_cache::add(), game::butcher(), color_in_inventory(), activity_handlers::firstaid_finish(), iuse_transform::info(), activity_handlers::longsalvage_finish(), item_action_generator::map_actions_to_items(), on_takeoff(), on_wear(), process_tool(), read(), active_item_cache::remove(), activity_handlers::repair_item_finish(), sleep(), activity_handlers::start_fire_finish(), avatar::wield(), avatar_action::wield(), and npc::wield_better_weapon().

◆ get_use_internal()

const use_function * item::get_use_internal ( const std::string &  use_name) const
private

Definition at line 7974 of file item.cpp.

7975{
7976 if( type != nullptr ) {
7977 return type->get_use( use_name );
7978 }
7979 return nullptr;
7980}

References itype::get_use(), and type.

Referenced by get_usable_item(), and get_use().

◆ get_var() [1/4]

std::string item::get_var ( const std::string &  name) const

Get the variable, if it does not exists, returns an empty string.

Definition at line 1073 of file item.cpp.

1074{
1075 return get_var( name, "" );
1076}

References get_var(), and om_direction::name().

◆ get_var() [2/4]

std::string item::get_var ( const std::string &  name,
const std::string &  default_value 
) const

Definition at line 1064 of file item.cpp.

1065{
1066 const auto it = item_vars.find( name );
1067 if( it == item_vars.end() ) {
1068 return default_value;
1069 }
1070 return it->second;
1071}

References item_vars, and om_direction::name().

◆ get_var() [3/4]

tripoint item::get_var ( const std::string &  name,
const tripoint default_value 
) const

Definition at line 1047 of file item.cpp.

1048{
1049 const auto it = item_vars.find( name );
1050 if( it == item_vars.end() ) {
1051 return default_value;
1052 }
1053 std::vector<std::string> values = string_split( it->second, ',' );
1054 return tripoint( atoi( values[0].c_str() ),
1055 atoi( values[1].c_str() ),
1056 atoi( values[2].c_str() ) );
1057}
std::vector< std::string > string_split(const std::string &text_in, char delim_in)
Split string by delimiter.

References item_vars, om_direction::name(), and string_split().

◆ get_var() [4/4]

◆ get_warmth()

int item::get_warmth ( ) const

Returns the warmth value that this item has when worn.

See player class for temperature related code, or player::warmth. Returned values should be positive. A value of 0 indicates no warmth from this item at all (this is also the default for non-armor).

Definition at line 5926 of file item.cpp.

5927{
5928 const islot_armor *t = find_armor_data();
5929 if( t == nullptr ) {
5930 return 0;
5931 }
5932 int result = t->warmth;
5933
5935
5936 return result;
5937}
@ clothing_mod_type_warmth
Definition: clothing_mod.h:23
int warmth
How much warmth this item provides.
Definition: itype.h:271

References clothing_mod_type_warmth, find_armor_data(), get_clothing_mod_val(), and islot_armor::warmth.

Referenced by armor_info(), armor_inventory_preset::armor_inventory_preset(), behavior::character_oracle_t::can_wear_warmer_clothes(), anonymous_namespace{armor_layers.cpp}::clothing_properties(), sew_advanced_actor::use(), and Character::warmth().

◆ get_weight_capacity_bonus()

units::mass item::get_weight_capacity_bonus ( ) const

Returns the weight capacity bonus (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 0. The bonus is added to the total weight capacity of the character that wears the item.

Definition at line 5762 of file item.cpp.

5763{
5764 const islot_armor *t = find_armor_data();
5765 if( t == nullptr ) {
5766 return 0_gram;
5767 }
5768 return t->weight_capacity_bonus;
5769}
units::mass weight_capacity_bonus
Bonus to weight capacity.
Definition: itype.h:283

References find_armor_data(), and islot_armor::weight_capacity_bonus.

Referenced by armor_info().

◆ get_weight_capacity_modifier()

float item::get_weight_capacity_modifier ( ) const

Returns the weight capacity modifier (islot_armor::weight_capacity_modifier) that this item provides when worn.

For non-armor it returns 1. The modifier is multiplied with the weight capacity of the character that wears the item.

Definition at line 5753 of file item.cpp.

5754{
5755 const islot_armor *t = find_armor_data();
5756 if( t == nullptr ) {
5757 return 1;
5758 }
5759 return t->weight_capacity_modifier;
5760}
float weight_capacity_modifier
Factor modifiying weight capacity.
Definition: itype.h:279

References find_armor_data(), and islot_armor::weight_capacity_modifier.

Referenced by armor_info().

◆ getlight()

bool item::getlight ( float &  luminance,
units::angle width,
units::angle direction 
) const

Directional light emission of the item.

Parameters
luminanceThe amount of light (see lightmap.cpp)
widthIf greater 0, the light is emitted in an arc, this is the angle of it.
directionThe direction of the light arc. In degrees.

Definition at line 8371 of file item.cpp.

8372{
8373 luminance = 0;
8374 width = 0_degrees;
8375 direction = 0_degrees;
8376 if( light.luminance > 0 ) {
8377 luminance = static_cast<float>( light.luminance );
8378 if( light.width > 0 ) { // width > 0 is a light arc
8379 width = units::from_degrees( light.width );
8381 }
8382 return true;
8383 } else {
8384 const int lumint = getlight_emit();
8385 if( lumint > 0 ) {
8386 luminance = static_cast<float>( lumint );
8387 return true;
8388 }
8389 }
8390 return false;
8391}
light_emission light
Definition: item.h:2237
int getlight_emit() const
How much light (see lightmap.cpp) the item emits (it's assumed to be circular).
Definition: item.cpp:8393
direction
Definition: line.h:39
constexpr quantity< double, angle_in_radians_tag > from_degrees(const value_type v)
Definition: units_angle.h:31
unsigned short luminance
Definition: item.h:90
short direction
Definition: item.h:92
short width
Definition: item.h:91

References light_emission::direction, units::from_degrees(), getlight_emit(), light, light_emission::luminance, and light_emission::width.

◆ getlight_emit()

int item::getlight_emit ( ) const

How much light (see lightmap.cpp) the item emits (it's assumed to be circular).

Definition at line 8393 of file item.cpp.

8394{
8395 float lumint = type->light_emission;
8396
8397 if( lumint == 0 ) {
8398 return 0;
8399 }
8400 if( has_flag( flag_CHARGEDIM ) && is_tool() && !has_flag( flag_USE_UPS ) ) {
8401 // Falloff starts at 1/5 total charge and scales linearly from there to 0.
8402 if( ammo_capacity() && ammo_remaining() < ( ammo_capacity() / 5 ) ) {
8403 lumint *= ammo_remaining() * 5.0 / ammo_capacity();
8404 }
8405 }
8406 return lumint;
8407}
static const std::string flag_CHARGEDIM("CHARGEDIM")
unsigned light_emission
Definition: itype.h:1000

References ammo_capacity(), ammo_remaining(), flag_CHARGEDIM(), flag_USE_UPS(), has_flag(), is_tool(), itype::light_emission, and type.

Referenced by Character::active_light(), and getlight().

◆ goes_bad()

bool item::goes_bad ( ) const

whether an item is perishable (can rot)

Definition at line 5506 of file item.cpp.

5507{
5510 }
5511 if( has_flag( flag_PROCESSING ) ) {
5512 return false;
5513 }
5514 if( is_corpse() ) {
5515 // Corpses rot only if they are made of rotting materials
5517 }
5518 return is_food() && get_comestible()->spoils != 0_turns;
5519}
bool made_of_any(const std::set< material_id > &mat_idents) const
Check we are made of at least one of a set (e.g.
Definition: item.cpp:6443
static const std::string flag_PROCESSING("PROCESSING")
bool goes_bad_cache_fetch()
Definition: item.cpp:337
bool goes_bad_cache_is_for(const item *i)
Definition: item.cpp:351
std::set< material_id > get_rotting()
Definition: material.cpp:327

References flag_PROCESSING(), get_comestible(), materials::get_rotting(), item_internal::goes_bad_cache_fetch(), item_internal::goes_bad_cache_is_for(), has_flag(), is_corpse(), is_food(), and made_of_any().

Referenced by actualize_rot(), basic_info(), crafting::can_disassemble(), complete_craft(), food_info(), get_most_rotten_component(), get_relative_rot(), get_shelf_life(), goes_bad_after_opening(), item_internal::goes_bad_cache_set(), item(), set_relative_rot(), spoilage_sort_order(), stacks_with(), and tname().

◆ goes_bad_after_opening()

bool item::goes_bad_after_opening ( ) const

whether an item is perishable (can rot), even if it is currently in a preserving container

Definition at line 5521 of file item.cpp.

5522{
5523 return goes_bad() || ( type->container && type->container->preserves &&
5524 !contents.empty() && contents.front().goes_bad() );
5525}

References itype::container, contents, item_contents::empty(), item_contents::front(), goes_bad(), and type.

◆ gun_all_modes()

std::map< gun_mode_id, gun_mode > item::gun_all_modes ( ) const

Get all possible modes for this gun inclusive of any attached gunmods.

Definition at line 7847 of file item.cpp.

7848{
7849 std::map<gun_mode_id, gun_mode> res;
7850
7851 if( !is_gun() || is_gunmod() ) {
7852 return res;
7853 }
7854
7855 std::vector<const item *> opts = gunmods();
7856 opts.push_back( this );
7857
7858 for( const item *e : opts ) {
7859
7860 // handle base item plus any auxiliary gunmods
7861 if( e->is_gun() ) {
7862 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gun->modes ) {
7863 // prefix attached gunmods, e.g. M203_DEFAULT to avoid index key collisions
7864 std::string prefix = e->is_gunmod() ? ( std::string( e->typeId() ) += "_" ) : "";
7865 std::transform( prefix.begin(), prefix.end(), prefix.begin(),
7866 static_cast<int( * )( int )>( toupper ) );
7867
7868 const int qty = m.second.qty();
7869
7870 res.emplace( gun_mode_id( prefix + m.first.str() ), gun_mode( m.second.name(),
7871 const_cast<item *>( e ),
7872 qty, m.second.flags() ) );
7873 }
7874
7875 // non-auxiliary gunmods may provide additional modes for the base item
7876 } else if( e->is_gunmod() ) {
7877 for( const std::pair<const gun_mode_id, gun_modifier_data> &m : e->type->gunmod->mode_modifier ) {
7878 //checks for melee gunmod, points to gunmod
7879 if( m.first == gun_mode_REACH ) {
7880 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( e ),
7881 m.second.qty(), m.second.flags() } );
7882 //otherwise points to the parent gun, not the gunmod
7883 } else {
7884 res.emplace( m.first, gun_mode { m.second.name(), const_cast<item *>( this ),
7885 m.second.qty(), m.second.flags() } );
7886 }
7887 }
7888 }
7889 }
7890
7891 return res;
7892}
static const gun_mode_id gun_mode_REACH("REACH")
string_id< gun_mode > gun_mode_id
Definition: type_id.h:68

References gun_mode_REACH, gunmods(), is_gun(), is_gunmod(), prefix, and iexamine::transform().

Referenced by target_ui::action_switch_mode(), npc_ai::best_mode_for_range(), can_fire_turret(), npc::confident_shoot_range(), gun_cycle_mode(), gun_get_mode(), gun_set_mode(), game::handle_action(), and reach_range().

◆ gun_current_mode()

gun_mode item::gun_current_mode ( ) const

Get the current mode for this gun (or an invalid mode if item is not a gun)

Definition at line 7906 of file item.cpp.

7907{
7908 return gun_get_mode( gun_get_mode_id() );
7909}
gun_mode_id gun_get_mode_id() const
Get id of mode a gun is currently set to, e.g.
Definition: item.cpp:7911
gun_mode gun_get_mode(const gun_mode_id &mode) const
Check if gun supports a specific mode returning an invalid/empty mode if not.
Definition: item.cpp:7894

References gun_get_mode(), and gun_get_mode_id().

Referenced by avatar_action::can_fire_weapon(), aim_activity_actor::do_turn(), target_ui::ensure_ranged_gun_mode(), npc::execute_action(), aim_activity_actor::finish(), fire(), turret_data::fire(), character_funcs::fmt_wielded_weapon(), info(), aim_activity_actor::load_RAS_weapon(), npc::method_of_attack(), target_ui::panel_fire_mode_aim(), target_ui::panel_gun_info(), turret_data::post_fire(), turret_data::prepare_fire(), print_aim(), turret_data::query(), gun_actor::shoot(), target_ui::update_ammo_range_from_gun_mode(), and target_ui::update_status().

◆ gun_cycle_mode()

void item::gun_cycle_mode ( )

Switch to the next available firing mode.

Definition at line 7928 of file item.cpp.

7929{
7930 if( !is_gun() || is_gunmod() ) {
7931 return;
7932 }
7933
7934 const gun_mode_id cur = gun_get_mode_id();
7935 const std::map<gun_mode_id, gun_mode> modes = gun_all_modes();
7936
7937 for( auto iter = modes.begin(); iter != modes.end(); ++iter ) {
7938 if( iter->first == cur ) {
7939 if( std::next( iter ) == modes.end() ) {
7940 break;
7941 }
7942 gun_set_mode( std::next( iter )->first );
7943 return;
7944 }
7945 }
7946 gun_set_mode( modes.begin()->first );
7947
7948 return;
7949}
std::map< gun_mode_id, gun_mode > gun_all_modes() const
Get all possible modes for this gun inclusive of any attached gunmods.
Definition: item.cpp:7847
bool gun_set_mode(const gun_mode_id &mode)
Try to set the mode for a gun, returning false if no such mode is possible.
Definition: item.cpp:7919

References gun_all_modes(), gun_get_mode_id(), gun_set_mode(), is_gun(), and is_gunmod().

Referenced by target_ui::ensure_ranged_gun_mode(), and game::handle_action().

◆ gun_damage()

damage_instance item::gun_damage ( bool  with_ammo = true) const

Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.

Returns empty instance on non-gun items.

Definition at line 7288 of file item.cpp.

7289{
7290 if( !is_gun() ) {
7291 return damage_instance();
7292 }
7293 damage_instance ret = type->gun->damage;
7294
7295 for( const item *mod : gunmods() ) {
7296 ret.add( mod->type->gunmod->damage );
7297 }
7298
7299 if( with_ammo && ammo_data() ) {
7300 ret.add( ammo_data()->ammo->damage );
7301 }
7302
7303 int item_damage = damage_level( 4 );
7304 if( item_damage > 0 ) {
7305 // TODO: This isn't a good solution for multi-damage guns/ammos
7306 for( damage_unit &du : ret ) {
7307 if( du.amount <= 1.0 ) {
7308 continue;
7309 }
7310 du.amount = std::max<float>( 1.0f, du.amount - item_damage * 2 );
7311 }
7312 }
7313
7314 return ret;
7315}

References ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), cata::hash64_detail::ret, and type.

Referenced by gun_info(), ideal_ranged_dps(), make_gun_projectile(), and weapon_inventory_preset::weapon_inventory_preset().

◆ gun_dispersion()

int item::gun_dispersion ( bool  with_ammo = true,
bool  with_scaling = true 
) const

Summed dispersion of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7241 of file item.cpp.

7242{
7243 if( !is_gun() ) {
7244 return 0;
7245 }
7246 int dispersion_sum = type->gun->dispersion;
7247 for( const item *mod : gunmods() ) {
7248 dispersion_sum += mod->type->gunmod->dispersion;
7249 }
7250 int dispPerDamage = get_option< int >( "DISPERSION_PER_GUN_DAMAGE" );
7251 dispersion_sum += damage_level( 4 ) * dispPerDamage;
7252 dispersion_sum = std::max( dispersion_sum, 0 );
7253 if( with_ammo && ammo_data() ) {
7254 dispersion_sum += ammo_data()->ammo->dispersion;
7255 }
7256 if( !with_scaling ) {
7257 return dispersion_sum;
7258 }
7259
7260 // Dividing dispersion by 15 temporarily as a gross adjustment,
7261 // will bake that adjustment into individual gun definitions in the future.
7262 // Absolute minimum gun dispersion is 1.
7263 double divider = get_option< float >( "GUN_DISPERSION_DIVIDER" );
7264 dispersion_sum = std::max( static_cast<int>( std::round( dispersion_sum / divider ) ), 1 );
7265
7266 return dispersion_sum;
7267}

References itype::ammo, ammo_data(), damage_level(), itype::gun, gunmods(), is_gun(), and type.

Referenced by gun_info().

◆ gun_get_mode()

gun_mode item::gun_get_mode ( const gun_mode_id mode) const

Check if gun supports a specific mode returning an invalid/empty mode if not.

Definition at line 7894 of file item.cpp.

7895{
7896 if( is_gun() ) {
7897 for( const std::pair<const gun_mode_id, gun_mode> &e : gun_all_modes() ) {
7898 if( e.first == mode ) {
7899 return e.second;
7900 }
7901 }
7902 }
7903 return gun_mode();
7904}

References gun_all_modes(), and is_gun().

Referenced by mattack::frag(), gun_current_mode(), mattack::rifle(), and mattack::tankgun().

◆ gun_get_mode_id()

gun_mode_id item::gun_get_mode_id ( ) const

Get id of mode a gun is currently set to, e.g.

DEFAULT, AUTO, BURST

Definition at line 7911 of file item.cpp.

7912{
7913 if( !is_gun() || is_gunmod() ) {
7914 return gun_mode_id();
7915 }
7916 return gun_mode_id( get_var( GUN_MODE_VAR_NAME, "DEFAULT" ) );
7917}
static const std::string GUN_MODE_VAR_NAME("item::mode")

References get_var(), GUN_MODE_VAR_NAME(), is_gun(), and is_gunmod().

Referenced by target_ui::action_switch_mode(), gun_current_mode(), and gun_cycle_mode().

◆ gun_info()

void item::gun_info ( const item mod,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2020 of file item.cpp.

2022{
2023 const std::string space = " ";
2024 const islot_gun &gun = *mod->type->gun;
2025 const Skill &skill = *mod->gun_skill();
2026 avatar &viewer = get_avatar();
2027
2028 // many statistics are dependent upon loaded ammo
2029 // if item is unloaded (or is RELOAD_AND_SHOOT) shows approximate stats using default ammo
2030 const item *loaded_mod = mod;
2031 item tmp;
2032 if( mod->ammo_required() && !mod->ammo_remaining() ) {
2033 tmp = *mod;
2034 tmp.ammo_set( mod->magazine_current() ? tmp.common_ammo_default() : tmp.ammo_default() );
2035 if( tmp.ammo_data() == nullptr ) {
2037 info.emplace_back( "GUN",
2038 _( "Weapon <bad>can't be loaded in its current state</bad>." ) );
2039 return;
2040 }
2041 loaded_mod = &tmp;
2042 if( parts->test( iteminfo_parts::GUN_DEFAULT_AMMO ) ) {
2044 info.emplace_back( "GUN",
2045 _( "Weapon is <bad>not loaded</bad>, so stats below assume the default ammo: " ),
2046 string_format( "<stat>%s</stat>",
2047 loaded_mod->ammo_data()->nname( 1 ) ) );
2048 }
2049 }
2050
2051 const itype *curammo = loaded_mod->ammo_data();
2052 if( mod->ammo_required() && !curammo ) {
2053 debugmsg( "curammo is nullptr in item::gun_info()" );
2054 return;
2055 }
2056 damage_unit gun_du = gun_damage( false ).damage_units.front();
2057
2059
2060 const damage_unit &ammo_du = curammo != nullptr
2061 ? curammo->ammo->damage.damage_units.front()
2062 : damage_unit( DT_STAB, 0 );
2063
2064 if( parts->test( iteminfo_parts::GUN_DAMAGE ) ) {
2066 info.push_back( iteminfo( "GUN", _( "<bold>Ranged damage</bold>: " ), "", iteminfo::no_newline,
2067 gun_du.amount ) );
2068 }
2069
2070 if( mod->ammo_required() ) {
2071 // ammo_damage, sum_of_damage, and ammo_mult not shown so don't need to translate.
2073 assert( curammo ); // Appease clang-tidy
2074 damage_instance ammo_dam = curammo->ammo->damage;
2075 info.push_back( iteminfo( "GUN", "ammo_damage", "",
2077 iteminfo::show_plus, ammo_du.amount ) );
2078 }
2079
2080 if( parts->test( iteminfo_parts::GUN_DAMAGE_TOTAL ) ) {
2081 // Intentionally not using total_damage() as it applies multipliers
2082 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2084 gun_du.amount + ammo_du.amount ) );
2085 }
2086 }
2087 info.back().bNewLine = true;
2088 avatar &you = get_avatar();
2089 int max_gun_range = loaded_mod->gun_range( &you );
2090 if( max_gun_range > 0 && parts->test( iteminfo_parts::GUN_MAX_RANGE ) ) {
2091 info.emplace_back( "GUN", _( "Maximum range: " ), "<num>", iteminfo::no_flags,
2092 max_gun_range );
2093 }
2094
2095 // TODO: This doesn't cover multiple damage types
2096 if( parts->test( iteminfo_parts::GUN_ARMORPIERCE ) ) {
2097 info.push_back( iteminfo( "GUN", _( "Armor-pierce: " ), "",
2099 }
2100 if( mod->ammo_required() ) {
2101 assert( curammo ); // Appease clang-tidy
2102 int ammo_pierce = get_ranged_pierce( *curammo->ammo );
2103 // ammo_armor_pierce and sum_of_armor_pierce don't need to translate.
2105 info.push_back( iteminfo( "GUN", "ammo_armor_pierce", "",
2107 iteminfo::show_plus, ammo_pierce ) );
2108 }
2110 info.push_back( iteminfo( "GUN", "sum_of_armor_pierce", _( " = <num>" ),
2112 get_ranged_pierce( gun ) + ammo_pierce ) );
2113 }
2114 }
2115 info.back().bNewLine = true;
2116
2117 if( parts->test( iteminfo_parts::GUN_DAMAGEMULT ) ) {
2118 info.push_back( iteminfo( "GUN", _( "Damage multiplier: " ), "",
2120 gun_du.damage_multiplier ) );
2121 }
2122
2123 if( mod->ammo_required() ) {
2125 info.push_back( iteminfo( "GUN", "ammo_mult", "*",
2127 ammo_du.damage_multiplier ) );
2128 }
2129
2131 info.push_back( iteminfo( "GUN", "sum_of_damage", _( " = <num>" ),
2133 gun_du.damage_multiplier * ammo_du.damage_multiplier ) );
2134 }
2135 }
2136 info.back().bNewLine = true;
2137
2138 if( parts->test( iteminfo_parts::GUN_ARMORMULT ) ) {
2139 info.push_back( iteminfo( "GUN", _( "Armor multiplier: " ), "",
2141 gun_du.res_mult ) );
2142 }
2143 if( mod->ammo_required() ) {
2145 info.push_back( iteminfo( "GUN", "ammo_armor_mult", _( "*<num>" ),
2148 ammo_du.res_mult ) );
2149 }
2151 info.push_back( iteminfo( "GUN", "final_armor_mult", _( " = <num>" ),
2153 gun_du.res_mult * ammo_du.res_mult ) );
2154 }
2155 }
2156 info.back().bNewLine = true;
2157
2158 if( parts->test( iteminfo_parts::GUN_DISPERSION ) ) {
2159 info.push_back( iteminfo( "GUN", _( "Dispersion: " ), "",
2161 mod->gun_dispersion( false, false ) ) );
2162 }
2163 if( mod->ammo_required() ) {
2164 int ammo_dispersion = curammo->ammo->dispersion;
2165 // ammo_dispersion and sum_of_dispersion don't need to translate.
2167 info.push_back( iteminfo( "GUN", "ammo_dispersion", "",
2170 ammo_dispersion ) );
2171 }
2173 info.push_back( iteminfo( "GUN", "sum_of_dispersion", _( " = <num>" ),
2175 loaded_mod->gun_dispersion( true, false ) ) );
2176 info.push_back( iteminfo( "GUN", "eff_dispersion", _( " (effective: <num>)" ),
2178 static_cast<int>( ranged::get_weapon_dispersion( you, *this ).max() ) ) );
2179 }
2180 }
2181 info.back().bNewLine = true;
2182
2183 // if effective sight dispersion differs from actual sight dispersion display both
2184 int act_disp = mod->sight_dispersion();
2185 int eff_disp = ranged::effective_dispersion( you, act_disp );
2186 int adj_disp = eff_disp - act_disp;
2187
2189 info.push_back( iteminfo( "GUN", _( "Sight dispersion: " ), "",
2191 act_disp ) );
2192
2193 if( adj_disp ) {
2194 info.push_back( iteminfo( "GUN", "sight_adj_disp", "",
2196 iteminfo::no_name | iteminfo::show_plus, adj_disp ) );
2197 info.push_back( iteminfo( "GUN", "sight_eff_disp", _( " = <num>" ),
2199 eff_disp ) );
2200 }
2201 }
2202
2203 bool bipod = mod->has_flag( flag_BIPOD );
2204
2205 if( loaded_mod->gun_recoil() ) {
2207 info.emplace_back( "GUN", _( "Recoil percentage: " ), "",
2209 std::ceil( 100 * loaded_mod->gun_recoil_multiplier() ) );
2210 }
2211 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_PERCENTAGE_BIPOD ) ) {
2212 info.emplace_back( "GUN", "bipod_recoil_percentage", _( " (with bipod <num>)" ),
2214 std::ceil( 100 * loaded_mod->gun_recoil_multiplier( true ) ) );
2215 }
2216 info.back().bNewLine = true;
2217
2218 if( parts->test( iteminfo_parts::GUN_RECOIL ) ) {
2219 info.emplace_back( "GUN", _( "Effective recoil: " ), "",
2221 loaded_mod->gun_recoil() );
2222 }
2223 if( bipod && parts->test( iteminfo_parts::GUN_RECOIL_BIPOD ) ) {
2224 info.emplace_back( "GUN", "bipod_recoil", _( " (with bipod <num>)" ),
2226 loaded_mod->gun_recoil( true ) );
2227 }
2228 }
2229 info.back().bNewLine = true;
2230
2231 std::map<gun_mode_id, gun_mode> fire_modes = mod->gun_all_modes();
2232 if( parts->test( iteminfo_parts::GUN_BURST_PENALTY ) ) {
2233 if( std::any_of( fire_modes.begin(), fire_modes.end(),
2234 []( const std::pair<gun_mode_id, gun_mode> &e ) {
2235 return e.second.qty > 1 && !e.second.melee();
2236 } ) ) {
2237 info.emplace_back( "GUN", _( "Burst fire penalty: " ), "",
2239 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil() ) );
2240 if( bipod ) {
2241 info.emplace_back( "GUN", "bipod_burst", _( " (with bipod <num>)" ),
2243 ranged::burst_penalty( you, *this, loaded_mod->gun_recoil( true ) ) );
2244 }
2245 }
2246 info.back().bNewLine = true;
2247 }
2248
2249 if( parts->test( iteminfo_parts::GUN_RELOAD_TIME ) ) {
2250 info.emplace_back( "GUN", _( "Reload time: " ),
2251 has_flag( flag_RELOAD_ONE ) ? _( "<num> moves per round" ) :
2252 _( "<num> moves " ),
2253 iteminfo::lower_is_better, mod->get_reload_time() );
2254 }
2255
2256 if( parts->test( iteminfo_parts::GUN_USEDSKILL ) ) {
2257 info.push_back( iteminfo( "GUN", _( "Skill used: " ),
2258 "<info>" + skill.name() + "</info>" ) );
2259 }
2260
2261 if( mod->magazine_integral() || mod->magazine_current() ) {
2262 if( mod->magazine_current() && parts->test( iteminfo_parts::GUN_MAGAZINE ) ) {
2263 info.emplace_back( "GUN", _( "Magazine: " ),
2264 string_format( "<stat>%s</stat>",
2265 mod->magazine_current()->tname() ) );
2266 }
2267 if( mod->ammo_capacity() && parts->test( iteminfo_parts::GUN_CAPACITY ) ) {
2268 for( const ammotype &at : mod->ammo_types() ) {
2269 const std::string fmt = string_format( vgettext( "<num> round of %s",
2270 "<num> rounds of %s",
2271 mod->ammo_capacity() ), at->name() );
2272 info.emplace_back( "GUN", _( "Capacity: " ), fmt, iteminfo::no_flags,
2273 mod->ammo_capacity() );
2274 }
2275 }
2276 } else if( parts->test( iteminfo_parts::GUN_TYPE ) ) {
2277 info.emplace_back( "GUN", _( "Type: " ), enumerate_as_string( mod->ammo_types().begin(),
2278 mod->ammo_types().end(), []( const ammotype & at ) {
2279 return at->name();
2281 }
2282
2283 if( mod->ammo_data() && parts->test( iteminfo_parts::AMMO_REMAINING ) ) {
2284 info.emplace_back( "AMMO", _( "Ammunition: " ), string_format( "<stat>%s</stat>",
2285 mod->ammo_data()->nname( mod->ammo_remaining() ) ) );
2286 }
2287
2288 if( mod->get_gun_ups_drain() && parts->test( iteminfo_parts::AMMO_UPSCOST ) ) {
2289 info.emplace_back( "AMMO",
2290 string_format( vgettext( "Uses <stat>%i</stat> charge of UPS per shot",
2291 "Uses <stat>%i</stat> charges of UPS per shot",
2292 mod->get_gun_ups_drain() ),
2293 mod->get_gun_ups_drain() ) );
2294 }
2295
2296 if( parts->test( iteminfo_parts::GUN_AIMING_STATS ) ) {
2298 info.emplace_back( "GUN", _( "<bold>Base aim speed</bold>: " ), "<num>", iteminfo::no_flags,
2300 for( const ranged::aim_type &type : ranged::get_aim_types( you, *mod ) ) {
2301 // Nameless aim levels don't get an entry.
2302 if( type.name.empty() ) {
2303 continue;
2304 }
2305 // For item comparison to work correctly each info object needs a
2306 // distinct tag per aim type.
2307 const std::string tag = "GUN_" + type.name;
2308 info.emplace_back( tag, string_format( "<info>%s</info>", type.name ) );
2309 int max_dispersion = ranged::get_weapon_dispersion( you, *loaded_mod ).max();
2310 int range = range_with_even_chance_of_good_hit( max_dispersion + type.threshold );
2311 info.emplace_back( tag, _( "Even chance of good hit at range: " ),
2312 _( "<num>" ), iteminfo::no_flags, range );
2313 int aim_mv = ranged::gun_engagement_moves( you, *mod, type.threshold );
2314 info.emplace_back( tag, _( "Time to reach aim level: " ), _( "<num> moves " ),
2315 iteminfo::lower_is_better, aim_mv );
2316 }
2317 }
2318
2319 if( parts->test( iteminfo_parts::GUN_FIRE_MODES ) ) {
2320 std::vector<std::string> fm;
2321 for( const std::pair<const gun_mode_id, gun_mode> &e : fire_modes ) {
2322 if( e.second.target == this && !e.second.melee() ) {
2323 fm.emplace_back( string_format( "%s (%i)", e.second.tname(), e.second.qty ) );
2324 }
2325 }
2326 if( !fm.empty() ) {
2328 info.emplace_back( "GUN", _( "<bold>Fire modes</bold>: " ) +
2329 enumerate_as_string( fm ) );
2330 }
2331 }
2332
2335 const std::set<itype_id> compat = magazine_compatible();
2336 info.emplace_back( "DESCRIPTION", _( "<bold>Compatible magazines</bold>: " ) +
2337 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
2338 return item::nname( id );
2339 } ) );
2340 }
2341
2342 if( !gun.valid_mod_locations.empty() && parts->test( iteminfo_parts::DESCRIPTION_GUN_MODS ) ) {
2344
2345 std::string mod_str = _( "<bold>Mods</bold>: " );
2346
2347 std::map<gunmod_location, int> mod_locations = get_mod_locations();
2348
2349 int iternum = 0;
2350 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2351 if( iternum != 0 ) {
2352 mod_str += "; ";
2353 }
2354 const int free_slots = ( elem ).second - get_free_mod_locations( elem.first );
2355 mod_str += string_format( "<bold>%d/%d</bold> %s", free_slots, elem.second,
2356 elem.first.name() );
2357 bool first_mods = true;
2358 for( const item *gmod : gunmods() ) {
2359 if( gmod->type->gunmod->location == ( elem ).first ) { // if mod for this location
2360 if( first_mods ) {
2361 mod_str += ": ";
2362 first_mods = false;
2363 } else {
2364 mod_str += ", ";
2365 }
2366 mod_str += string_format( "<stat>%s</stat>", gmod->tname() );
2367 }
2368 }
2369 iternum++;
2370 }
2371 mod_str += ".";
2372 info.push_back( iteminfo( "DESCRIPTION", mod_str ) );
2373 }
2374
2375 if( mod->casings_count() && parts->test( iteminfo_parts::DESCRIPTION_GUN_CASINGS ) ) {
2377 std::string tmp = vgettext( "Contains <stat>%i</stat> casing",
2378 "Contains <stat>%i</stat> casings", mod->casings_count() );
2379 info.emplace_back( "DESCRIPTION", string_format( tmp, mod->casings_count() ) );
2380 }
2381}
@ range
Definition: character.h:104
Definition: skill.h:33
double max() const
Definition: dispersion.cpp:20
int gun_recoil(bool bipod=false) const
Get effective recoil considering handling, loaded ammo and effects of attached gunmods.
Definition: item.cpp:7337
itype_id common_ammo_default(bool conversion=true) const
Get default ammo for the first ammotype common to an item and its current magazine or "NULL" if none ...
Definition: item.cpp:7625
int get_free_mod_locations(const gunmod_location &location) const
Number of mods that can still be installed into the given mod location, for non-guns it always return...
Definition: item.cpp:4098
damage_instance gun_damage(bool with_ammo=true) const
Summed ranged damage, armor piercing, and multipliers for both, of a gun, including values from mods.
Definition: item.cpp:7288
int gun_dispersion(bool with_ammo=true, bool with_scaling=true) const
Summed dispersion of a gun, including values from mods.
Definition: item.cpp:7241
double gun_recoil_multiplier(bool bipod=false) const
Get multiplier on recoil considering handling and attached gunmods.
Definition: item.cpp:7317
int gun_range(const player *p) const
The weapons range in map squares.
Definition: item.cpp:7370
bool empty() const
Whether the underlying string is empty, not matter what the context is or whether translation is need...
constexpr double MAX_RECOIL
static const std::string flag_RELOAD_ONE("RELOAD_ONE")
static const std::string flag_BIPOD("BIPOD")
@ GUN_ARMORPIERCE_LOADEDAMMO
@ GUN_RECOIL_PERCENTAGE_BIPOD
int gun_engagement_moves(const Character &who, const item &gun, int target=0, int start=MAX_RECOIL)
How many moves does it take to aim gun to the target accuracy.
Definition: ranged.cpp:583
float str_draw_damage_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1034
int burst_penalty(const Character &p, const item &gun, int gun_recoil)
Definition: ranged.cpp:2163
std::vector< aim_type > get_aim_types(const Character &who, const item &gun)
Definition: ranged.cpp:1653
int effective_dispersion(const Character &who, int dispersion)
Definition: ranged.cpp:3815
dispersion_sources get_weapon_dispersion(const Character &who, const item &obj)
Get weapon's dispersion value modified accoring to character stats.
Definition: ranged.cpp:1920
double aim_per_move(const Character &who, const item &gun, double recoil)
Calculates aim improvement per move spent aiming at a given.
Definition: ranged.cpp:3914
int range_with_even_chance_of_good_hit(int dispersion)
Definition: ranged.cpp:572
float amount
Definition: damage.h:37
float res_mult
Definition: damage.h:39
std::map< gunmod_location, int > valid_mod_locations
Location for gun mods.
Definition: itype.h:520
@ no_name
Do not print the name.
Definition: item.h:149
translation name
unique string identifier for this type
Definition: itype.h:887

References _, ranged::aim_per_move(), itype::ammo, ammo_data(), ammo_default(), AMMO_REMAINING, ammo_set(), AMMO_UPSCOST, damage_unit::amount, ranged::burst_penalty(), common_ammo_default(), curammo, damage_unit::damage_multiplier, damage_instance::damage_units, debugmsg, DESCRIPTION_GUN_CASINGS, DESCRIPTION_GUN_MODS, DT_STAB, ranged::effective_dispersion(), translation::empty(), enumerate_as_string(), flag_BIPOD(), flag_RELOAD_ONE(), ranged::get_aim_types(), get_avatar(), get_free_mod_locations(), get_mod_locations(), get_ranged_pierce(), ranged::get_weapon_dispersion(), GUN_AIMING_STATS, GUN_ALLOWED_MAGAZINES, GUN_ARMORMULT, GUN_ARMORMULT_LOADEDAMMO, GUN_ARMORMULT_TOTAL, GUN_ARMORPIERCE, GUN_ARMORPIERCE_LOADEDAMMO, GUN_ARMORPIERCE_TOTAL, GUN_BURST_PENALTY, GUN_CAPACITY, gun_damage(), GUN_DAMAGE, GUN_DAMAGE_LOADEDAMMO, GUN_DAMAGE_TOTAL, GUN_DAMAGEMULT, GUN_DAMAGEMULT_AMMO, GUN_DAMAGEMULT_TOTAL, GUN_DEFAULT_AMMO, gun_dispersion(), GUN_DISPERSION, GUN_DISPERSION_LOADEDAMMO, GUN_DISPERSION_SIGHT, GUN_DISPERSION_TOTAL, ranged::gun_engagement_moves(), GUN_FIRE_MODES, GUN_MAGAZINE, GUN_MAX_RANGE, gun_range(), gun_recoil(), GUN_RECOIL, GUN_RECOIL_BIPOD, gun_recoil_multiplier(), GUN_RECOIL_PERCENTAGE, GUN_RECOIL_PERCENTAGE_BIPOD, GUN_RELOAD_TIME, GUN_TYPE, GUN_USEDSKILL, gunmods(), has_flag(), info(), insert_separation_line(), iteminfo::is_decimal, iteminfo::lower_is_better, magazine_compatible(), magazine_integral(), dispersion_sources::max(), MAX_RECOIL, itype::name, Skill::name(), itype::nname(), iteminfo::no_flags, iteminfo::no_name, iteminfo::no_newline, none, range, range_with_even_chance_of_good_hit(), damage_unit::res_mult, second, iteminfo::show_plus, sign::space, ranged::str_draw_damage_modifier(), string_format(), iteminfo_query::test(), type, islot_gun::valid_mod_locations, and vgettext().

Referenced by info().

◆ gun_noise()

item::sound_data item::gun_noise ( bool  burst = false) const

Returns the sound of the gun being fired.

Parameters
burstWhether the gun was fired in burst mode (the sound string is usually different).

Definition at line 1815 of file ranged.cpp.

1816{
1817 if( !is_gun() ) {
1818 return { 0, "" };
1819 }
1820
1821 int noise = type->gun->loudness;
1822 for( const auto mod : gunmods() ) {
1823 noise += mod->type->gunmod->loudness;
1824 }
1825 if( ammo_data() ) {
1826 noise += ammo_data()->ammo->loudness;
1827 }
1828
1829 noise = std::max( noise, 0 );
1830
1832 // Grenade launchers
1833 return { 8, _( "Thunk!" ) };
1834
1835 } else if( ammo_current() == itype_12mm || ammo_current() == itype_metal_rail ) {
1836 // Railguns
1837 return { 24, _( "tz-CRACKck!" ) };
1838
1839 } else if( ammo_current() == itype_flammable || ammo_current() == itype_66mm ||
1841 // Rocket launchers and flamethrowers
1842 return { 4, _( "Fwoosh!" ) };
1843 } else if( ammo_current() == itype_arrow ) {
1844 return { noise, _( "whizz!" ) };
1845 } else if( ammo_current() == itype_bolt ) {
1846 return { noise, _( "thonk!" ) };
1847 }
1848
1849 auto fx = ammo_effects();
1850
1851 if( fx.count( ammo_effect_LASER ) || fx.count( ammo_effect_PLASMA ) ) {
1852 if( noise < 20 ) {
1853 return { noise, _( "Fzzt!" ) };
1854 } else if( noise < 40 ) {
1855 return { noise, _( "Pew!" ) };
1856 } else if( noise < 60 ) {
1857 return { noise, _( "Tsewww!" ) };
1858 } else {
1859 return { noise, _( "Kra-kow!" ) };
1860 }
1861
1862 } else if( fx.count( ammo_effect_LIGHTNING ) ) {
1863 if( noise < 20 ) {
1864 return { noise, _( "Bzzt!" ) };
1865 } else if( noise < 40 ) {
1866 return { noise, _( "Bzap!" ) };
1867 } else if( noise < 60 ) {
1868 return { noise, _( "Bzaapp!" ) };
1869 } else {
1870 return { noise, _( "Kra-koom!" ) };
1871 }
1872
1873 } else if( fx.count( ammo_effect_WHIP ) ) {
1874 return { noise, _( "Crack!" ) };
1875
1876 } else if( noise > 0 ) {
1877 if( noise < 10 ) {
1878 return { noise, burst ? _( "Brrrip!" ) : _( "plink!" ) };
1879 } else if( noise < 150 ) {
1880 return { noise, burst ? _( "Brrrap!" ) : _( "bang!" ) };
1881 } else if( noise < 175 ) {
1882 return { noise, burst ? _( "P-p-p-pow!" ) : _( "blam!" ) };
1883 } else {
1884 return { noise, burst ? _( "Kaboom!" ) : _( "kerblam!" ) };
1885 }
1886 }
1887
1888 return { 0, "" }; // silent weapons
1889}
std::set< ammo_effect_str_id > ammo_effects(bool with_ammo=true) const
Get ammo effects for item optionally inclusive of any resulting from the loaded ammo.
Definition: item.cpp:7641
static const ammo_effect_str_id ammo_effect_WHIP("WHIP")
static const ammo_effect_str_id ammo_effect_LIGHTNING("LIGHTNING")
static const itype_id itype_12mm("12mm")
static const itype_id itype_flammable("flammable")
static const itype_id itype_m235("m235")
static const ammo_effect_str_id ammo_effect_LASER("LASER")
static const itype_id itype_40x46mm("40x46mm")
static const itype_id itype_40x53mm("40x53mm")
static const itype_id itype_bolt("bolt")
static const itype_id itype_84x246mm("84x246mm")
static const itype_id itype_metal_rail("metal_rail")
static const ammo_effect_str_id ammo_effect_PLASMA("PLASMA")
static const itype_id itype_66mm("66mm")
static const itype_id itype_arrow("arrow")

References _, itype::ammo, ammo_current(), ammo_data(), ammo_effect_LASER, ammo_effect_LIGHTNING, ammo_effect_PLASMA, ammo_effect_WHIP, ammo_effects(), itype::gun, gunmods(), is_gun(), itype_12mm, itype_40x46mm, itype_40x53mm, itype_66mm, itype_84x246mm, itype_arrow, itype_bolt, itype_flammable, itype_m235, itype_metal_rail, noise, and type.

Referenced by is_silent(), ranged::make_gun_sound_effect(), and npc::pretend_fire().

◆ gun_range() [1/2]

int item::gun_range ( bool  with_ammo = true) const

Summed range value of a gun, including values from mods.

Returns 0 on non-gun items.

Definition at line 7351 of file item.cpp.

7352{
7353 if( !is_gun() ) {
7354 return 0;
7355 }
7356 int ret = type->gun->range;
7357 for( const item *mod : gunmods() ) {
7358 ret += mod->type->gunmod->range;
7359 }
7360 if( with_ammo && ammo_data() ) {
7361 if( ammo_data()->ammo->shape ) {
7362 ret = ammo_data()->ammo->shape->get_range();
7363 } else {
7364 ret += ammo_data()->ammo->range;
7365 }
7366 }
7367 return std::min( std::max( 0, ret ), RANGE_HARD_CAP );
7368}
static constexpr int RANGE_HARD_CAP

References itype::ammo, ammo_data(), itype::gun, gunmods(), is_gun(), RANGE_HARD_CAP, cata::hash64_detail::ret, and type.

◆ gun_range() [2/2]

int item::gun_range ( const player p) const

The weapons range in map squares.

If the item has an active gunmod, it returns the range of that gunmod, the guns range is returned only when the item has no active gunmod. This function applies to guns and auxiliary gunmods. For other items, 0 is returned. It includes the range given by the ammo.

Parameters
pThe player that uses the weapon, their strength might affect this. It's optional and can be null.

Definition at line 7370 of file item.cpp.

7371{
7372 int ret = gun_range( true );
7373 if( p == nullptr ) {
7374 return ret;
7375 }
7376 if( !p->meets_requirements( *this ) ) {
7377 return 0;
7378 }
7379
7380 // Reduce bow range if player has less than minimum strength.
7381 ret *= ranged::str_draw_range_modifier( *this, *p );
7382
7383 return std::max( 0, ret );
7384}
bool meets_requirements(const item &it, const item &context=item()) const
Checks whether the character meets overall requirements to be able to use the item.
Definition: character.cpp:3546
float str_draw_range_modifier(const item &it, const Character &p)
Definition: ranged.cpp:1060

References gun_range(), Character::meets_requirements(), cata::hash64_detail::ret, and ranged::str_draw_range_modifier().

Referenced by gun_info(), gun_range(), game::list_monsters(), make_gun_projectile(), turret_data::range(), and target_ui::update_ammo_range_from_gun_mode().

◆ gun_recoil()

int item::gun_recoil ( bool  bipod = false) const

Get effective recoil considering handling, loaded ammo and effects of attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
effective recoil (per shot) or zero if gun uses ammo and none is loaded

Definition at line 7337 of file item.cpp.

7338{
7339 if( !is_gun() || ( ammo_required() && !ammo_remaining() ) ) {
7340 return 0;
7341 }
7342
7343 int qty = type->gun->recoil;
7344 if( ammo_data() ) {
7345 qty += ammo_data()->ammo->recoil;
7346 }
7347
7348 return qty * gun_recoil_multiplier( bipod );
7349}

References itype::ammo, ammo_data(), ammo_remaining(), ammo_required(), itype::gun, gun_recoil_multiplier(), is_gun(), and type.

Referenced by calculate_dispersion(), npc::confident_gun_mode_range(), ranged::fire_gun(), and gun_info().

◆ gun_recoil_multiplier()

double item::gun_recoil_multiplier ( bool  bipod = false) const

Get multiplier on recoil considering handling and attached gunmods.

Parameters
bipodwhether any bipods should be considered
Returns
multiplier on recoil applied to shots fired from this gun

Definition at line 7317 of file item.cpp.

7318{
7319 double handling = type->gun->handling;
7320 for( const item *mod : gunmods() ) {
7321 if( bipod || !mod->has_flag( flag_BIPOD ) ) {
7322 handling += mod->type->gunmod->handling;
7323 }
7324 }
7325
7326 // Rescale from JSON units which are intentionally specified as integral values
7327 handling /= 10;
7328
7329 // Handling will almost always be above 1.0
7330 if( handling > 1.0 ) {
7331 return 1.0 / handling;
7332 } else {
7333 return 2.0 - handling;
7334 }
7335}

References flag_BIPOD(), itype::gun, gunmods(), and type.

Referenced by gun_info(), and gun_recoil().

◆ gun_set_mode()

bool item::gun_set_mode ( const gun_mode_id mode)

Try to set the mode for a gun, returning false if no such mode is possible.

Definition at line 7919 of file item.cpp.

7920{
7921 if( !is_gun() || is_gunmod() || !gun_all_modes().count( mode ) ) {
7922 return false;
7923 }
7924 set_var( GUN_MODE_VAR_NAME, mode.str() );
7925 return true;
7926}

References count(), gun_all_modes(), GUN_MODE_VAR_NAME(), is_gun(), is_gunmod(), set_var(), and string_id< T >::str().

Referenced by target_ui::action_switch_mode(), gun_cycle_mode(), avatar_funcs::gunmod_remove(), game::handle_action(), io(), and gun_actor::shoot().

◆ gun_skill()

◆ gun_type()

gun_type_type item::gun_type ( ) const

Get the type of a ranged weapon (e.g.

"rifle", "crossbow"), or empty string if non-gun

Definition at line 7203 of file item.cpp.

7204{
7205 if( !is_gun() ) {
7206 return gun_type_type( std::string() );
7207 }
7208 if( has_flag( flag_CROSSBOW ) ) {
7209 return gun_type_type( translate_marker_context( "gun_type_type", "crossbow" ) );
7210 }
7211 // TODO: move to JSON and remove extraction of this from "GUN" (via skill id)
7212 //and from "GUNMOD" (via "mod_targets") in lang/extract_json_strings.py
7213 return gun_type_type( gun_skill().str() );
7214}
The type of gun. The second "_type" suffix is only to distinguish it from item::gun_type.
Definition: itype.h:548
static const std::string flag_CROSSBOW("CROSSBOW")
#define translate_marker_context(c, x)
Same as translate_marker, but also provides a context (string literal).
Definition: translations.h:38

References flag_CROSSBOW(), gun_skill(), has_flag(), is_gun(), and translate_marker_context.

Referenced by is_gunmod_compatible().

◆ gunmod_find() [1/2]

item * item::gunmod_find ( const itype_id mod)

Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.

Definition at line 7758 of file item.cpp.

7759{
7760 std::vector<item *> mods = gunmods();
7761 auto it = std::find_if( mods.begin(), mods.end(), [&mod]( item * e ) {
7762 return e->typeId() == mod;
7763 } );
7764 return it != mods.end() ? *it : nullptr;
7765}

References gunmods().

Referenced by saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), cycle_action(), gunmod_find(), is_gunmod_compatible(), tname(), volume(), and weight().

◆ gunmod_find() [2/2]

const item * item::gunmod_find ( const itype_id mod) const

Definition at line 7767 of file item.cpp.

7768{
7769 return const_cast<item *>( this )->gunmod_find( mod );
7770}
item * gunmod_find(const itype_id &mod)
Get first attached gunmod matching type or nullptr if no such mod or item is not a gun.
Definition: item.cpp:7758

References gunmod_find().

◆ gunmod_info()

void item::gunmod_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 2383 of file item.cpp.

2385{
2386 if( !is_gunmod() ) {
2387 return;
2388 }
2389 const islot_gunmod &mod = *type->gunmod;
2390
2391 if( is_gun() && parts->test( iteminfo_parts::DESCRIPTION_GUNMOD ) ) {
2392 info.push_back( iteminfo( "DESCRIPTION",
2393 _( "This mod <info>must be attached to a gun</info>, "
2394 "it can not be fired separately." ) ) );
2395 }
2397 info.push_back( iteminfo( "DESCRIPTION",
2398 _( "When attached to a gun, <good>allows</good> making "
2399 "<info>reach melee attacks</info> with it." ) ) );
2400 }
2401 if( mod.dispersion != 0 && parts->test( iteminfo_parts::GUNMOD_DISPERSION ) ) {
2402 info.push_back( iteminfo( "GUNMOD", _( "Dispersion modifier: " ), "",
2404 mod.dispersion ) );
2405 }
2406 if( mod.sight_dispersion != -1 && parts->test( iteminfo_parts::GUNMOD_DISPERSION_SIGHT ) ) {
2407 info.push_back( iteminfo( "GUNMOD", _( "Sight dispersion: " ), "",
2408 iteminfo::lower_is_better, mod.sight_dispersion ) );
2409 }
2410 if( mod.aim_speed >= 0 && parts->test( iteminfo_parts::GUNMOD_AIMSPEED ) ) {
2411 info.push_back( iteminfo( "GUNMOD", _( "Aim speed: " ), "",
2412 iteminfo::lower_is_better, mod.aim_speed ) );
2413 }
2414 int total_damage = static_cast<int>( mod.damage.total_damage() );
2415 if( total_damage != 0 && parts->test( iteminfo_parts::GUNMOD_DAMAGE ) ) {
2416 info.push_back( iteminfo( "GUNMOD", _( "Damage: " ), "", iteminfo::show_plus,
2417 total_damage ) );
2418 }
2419 int pierce = get_ranged_pierce( mod );
2421 info.push_back( iteminfo( "GUNMOD", _( "Armor-pierce: " ), "", iteminfo::show_plus,
2422 pierce ) );
2423 }
2424 if( mod.handling != 0 && parts->test( iteminfo_parts::GUNMOD_HANDLING ) ) {
2425 info.emplace_back( "GUNMOD", _( "Handling modifier: " ), "",
2426 iteminfo::show_plus, mod.handling );
2427 }
2428 if( !type->mod->ammo_modifier.empty() && parts->test( iteminfo_parts::GUNMOD_AMMO ) ) {
2429 for( const ammotype &at : type->mod->ammo_modifier ) {
2430 info.push_back( iteminfo( "GUNMOD", string_format( _( "Ammo: <stat>%s</stat>" ),
2431 at->name() ) ) );
2432 }
2433 }
2434 if( mod.reload_modifier != 0 && parts->test( iteminfo_parts::GUNMOD_RELOAD ) ) {
2435 info.emplace_back( "GUNMOD", _( "Reload modifier: " ), _( "<num>%" ),
2436 iteminfo::lower_is_better, mod.reload_modifier );
2437 }
2438 if( mod.min_str_required_mod > 0 && parts->test( iteminfo_parts::GUNMOD_STRENGTH ) ) {
2439 info.push_back( iteminfo( "GUNMOD", _( "Minimum strength required modifier: " ),
2440 mod.min_str_required_mod ) );
2441 }
2442 if( !mod.add_mod.empty() && parts->test( iteminfo_parts::GUNMOD_ADD_MOD ) ) {
2444
2445 std::string mod_loc_str = _( "<bold>Adds mod locations: </bold> " );
2446
2447 std::map<gunmod_location, int> mod_locations = mod.add_mod;
2448
2449 int iternum = 0;
2450 for( std::pair<const gunmod_location, int> &elem : mod_locations ) {
2451 if( iternum != 0 ) {
2452 mod_loc_str += "; ";
2453 }
2454 mod_loc_str += string_format( "<bold>%s</bold> %s", elem.second, elem.first.name() );
2455 iternum++;
2456 }
2457 mod_loc_str += ".";
2458 info.push_back( iteminfo( "GUNMOD", mod_loc_str ) );
2459 }
2460
2462
2463 if( parts->test( iteminfo_parts::GUNMOD_USEDON ) ) {
2464 std::string used_on_str = _( "Used on: " ) +
2465 enumerate_as_string( mod.usable.begin(), mod.usable.end(), []( const gun_type_type & used_on ) {
2466 return string_format( "<info>%s</info>", used_on.name() );
2467 } );
2468 info.push_back( iteminfo( "GUNMOD", used_on_str ) );
2469 }
2470
2471 if( parts->test( iteminfo_parts::GUNMOD_LOCATION ) ) {
2472 info.push_back( iteminfo( "GUNMOD", string_format( _( "Location: %s" ),
2473 mod.location.name() ) ) );
2474 }
2475
2476 if( !mod.blacklist_mod.empty() && parts->test( iteminfo_parts::GUNMOD_BLACKLIST_MOD ) ) {
2477 std::string mod_black_str = _( "<bold>Incompatible with mod location: </bold> " );
2478
2479 int iternum = 0;
2480 for( const gunmod_location &black : mod.blacklist_mod ) {
2481 if( iternum != 0 ) {
2482 mod_black_str += ", ";
2483 }
2484 mod_black_str += string_format( "%s", black.name() );
2485 iternum++;
2486 }
2487 mod_black_str += ".";
2488 info.push_back( iteminfo( "GUNMOD", mod_black_str ) );
2489 }
2490}
cata::value_ptr< islot_gunmod > gunmod
Definition: itype.h:860
cata::value_ptr< islot_mod > mod
Definition: itype.h:855

References _, catacurses::black, DESCRIPTION_GUNMOD, DESCRIPTION_GUNMOD_REACH, enumerate_as_string(), flag_REACH_ATTACK(), get_ranged_pierce(), itype::gunmod, GUNMOD_ADD_MOD, GUNMOD_AIMSPEED, GUNMOD_AMMO, GUNMOD_ARMORPIERCE, GUNMOD_BLACKLIST_MOD, GUNMOD_DAMAGE, GUNMOD_DISPERSION, GUNMOD_DISPERSION_SIGHT, GUNMOD_HANDLING, GUNMOD_LOCATION, GUNMOD_RELOAD, GUNMOD_STRENGTH, GUNMOD_USEDON, has_flag(), info(), insert_separation_line(), is_gun(), is_gunmod(), iteminfo::lower_is_better, itype::mod, ammunition_type::name(), iteminfo::show_plus, string_format(), iteminfo_query::test(), and type.

Referenced by info().

◆ gunmods() [1/2]

◆ gunmods() [2/2]

std::vector< const item * > item::gunmods ( ) const

Definition at line 7753 of file item.cpp.

7754{
7755 return contents.gunmods();
7756}

References contents, and item_contents::gunmods().

◆ handle_craft_failure()

bool item::handle_craft_failure ( player crafter)

Handle failure during crafting.

Destroy components, lose progress, and set a new failure point.

Parameters
crafterthe crafting player.
Returns
whether the craft being worked on should be entirely destroyed

Definition at line 930 of file crafting.cpp.

931{
932 if( !is_craft() ) {
933 debugmsg( "handle_craft_failure() called on non-craft '%s.' Aborting.", tname() );
934 return false;
935 }
936
937 const double success_roll = crafter.crafting_success_roll( get_making() );
938 const int starting_components = this->components.size();
939 // Destroy at most 75% of the components, always a chance of losing 1 though
940 const size_t max_destroyed = std::max<size_t>( 1, components.size() * 3 / 4 );
941 for( size_t i = 0; i < max_destroyed; i++ ) {
942 // This shouldn't happen
943 if( components.empty() ) {
944 break;
945 }
946 // If we roll success, skip destroying a component
947 if( x_in_y( success_roll, 1.0 ) ) {
948 continue;
949 }
950 destroy_random_component( *this, crafter );
951 }
952 if( starting_components > 0 && this->components.empty() ) {
953 // The craft had components and all of them were destroyed.
954 return true;
955 }
956
957 // Minimum 25% progress lost, average 35%. Falls off exponentially
958 // Loss is scaled by the success roll
959 const double percent_progress_loss = rng_exponential( 0.25, 0.35 ) *
960 ( 1.0 - std::min( success_roll, 1.0 ) );
961 const int progess_loss = item_counter * percent_progress_loss;
962 crafter.add_msg_player_or_npc( _( "You mess up and lose %d%% progress." ),
963 _( "<npcname> messes up and loses %d%% progress." ), progess_loss / 100000 );
964 item_counter = clamp( item_counter - progess_loss, 0, 10000000 );
965
966 set_next_failure_point( crafter );
967
968 // Check if we can consume a new component and continue
969 if( !crafter.can_continue_craft( *this ) ) {
970 crafter.cancel_activity();
971 }
972 return false;
973}
bool x_in_y(const time_duration &a, const time_duration &b)
Definition: calendar.cpp:521
constexpr T clamp(const T &val, const T &min, const T &max)
Clamp first argument so that it is no lower than second and no higher than third.
Definition: cata_utility.h:149
void cancel_activity()
Definition: character.cpp:9234
const recipe & get_making() const
Get the stored recipe for in progress crafts.
Definition: item.cpp:10110
void set_next_failure_point(const player &crafter)
Calculates and sets the next failure point for an in progress craft.
Definition: crafting.cpp:904
void add_msg_player_or_npc(const std::string &player_msg, const std::string &npc_str) const override
Definition: player.cpp:371
bool can_continue_craft(item &craft)
Check if the player meets the requirements to continue the in progress craft and if unable to continu...
Definition: crafting.cpp:1161
double crafting_success_roll(const recipe &making) const
Calculate a value representing the success of the player at crafting the given recipe,...
Definition: crafting.cpp:820
static void destroy_random_component(item &craft, const player &crafter)
Definition: crafting.cpp:917
double rng_exponential(double min, double mean)
Definition: rng.cpp:55

References _, player::add_msg_player_or_npc(), player::can_continue_craft(), Character::cancel_activity(), clamp(), components, player::crafting_success_roll(), debugmsg, destroy_random_component(), get_making(), is_craft(), item_counter, rng_exponential(), set_next_failure_point(), tname(), and x_in_y().

◆ handle_pickup_ownership()

void item::handle_pickup_ownership ( Character c)

Definition at line 4479 of file item.cpp.

4480{
4481 if( is_owned_by( c ) ) {
4482 return;
4483 }
4484 // Add ownership to item if unowned
4485 if( owner.is_null() ) {
4486 set_owner( c );
4487 } else {
4489 if( !is_owned_by( c ) && &c == &you ) {
4490 std::vector<npc *> witnesses;
4491 for( npc &elem : g->all_npcs() ) {
4492 if( rl_dist( elem.pos(), you.pos() ) < MAX_VIEW_DISTANCE && elem.get_faction() &&
4493 is_owned_by( elem ) && elem.sees( you.pos() ) ) {
4494 elem.say( "<witnessed_thievery>", 7 );
4495 npc *npc_to_add = &elem;
4496 witnesses.push_back( npc_to_add );
4497 }
4498 }
4499 if( !witnesses.empty() ) {
4501 // Make sure there is only one witness
4502 for( npc &guy : g->all_npcs() ) {
4503 if( guy.get_attitude() == NPCATT_RECOVER_GOODS ) {
4504 guy.set_attitude( NPCATT_NULL );
4505 }
4506 }
4507 random_entry( witnesses )->set_attitude( NPCATT_RECOVER_GOODS );
4508 // Notify the activity that we got a witness
4509 if( c.activity && !c.activity.is_null() && c.activity.id() == ACT_PICKUP ) {
4510 c.activity.str_values.clear();
4511 c.activity.str_values.emplace_back( has_thievery_witness );
4512 }
4513 }
4514 set_owner( c );
4515 }
4516 }
4517}
const tripoint & pos() const override
Definition: character.cpp:599
bool is_owned_by(const Character &c, bool available_to_take=false) const
Definition: item.cpp:1237
void set_old_owner(const faction_id &temp_owner)
Definition: item.h:2023
void set_owner(const faction_id &new_owner)
Definition: item.h:2029
Definition: npc.h:744
int rl_dist(const coords::coord_point< Point, Origin, Scale > &loc1, const coords::coord_point< Point, Origin, Scale > &loc2)
Definition: coordinates.h:519
static constexpr int MAX_VIEW_DISTANCE
static const activity_id ACT_PICKUP("ACT_PICKUP")
static const std::string has_thievery_witness("has_thievery_witness")
@ NPCATT_NULL
Definition: npc.h:81
@ NPCATT_RECOVER_GOODS
Definition: npc.h:100

References ACT_PICKUP, c, g, get_owner(), get_player_character(), has_thievery_witness(), string_id< T >::is_null(), is_owned_by(), MAX_VIEW_DISTANCE, NPCATT_NULL, NPCATT_RECOVER_GOODS, owner, Character::pos(), random_entry(), rl_dist(), set_old_owner(), and set_owner().

Referenced by on_pickup(), on_wear(), and on_wield().

◆ has_any_flag()

template<typename Container , typename T = std::decay_t<decltype( *std::declval<const Container &>().begin() )>>
bool item::has_any_flag ( const Container &  flags) const
inline

Definition at line 1408 of file item.h.

1408 {
1409 return std::any_of( flags.begin(), flags.end(), [&]( const T & flag ) {
1410 return has_flag( flag );
1411 } );
1412 }

Referenced by Character::can_eat(), and Character::consume_effects().

◆ has_clothing_mod()

bool item::has_clothing_mod ( ) const

Definition at line 10154 of file item.cpp.

10155{
10156 for( const clothing_mod &cm : clothing_mods::get_all() ) {
10157 if( has_own_flag( cm.flag ) ) {
10158 return true;
10159 }
10160 }
10161 return false;
10162}
const std::vector< clothing_mod > & get_all()

References clothing_mods::get_all(), and has_own_flag().

Referenced by tname().

◆ has_effect_when_carried()

bool item::has_effect_when_carried ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is carried?

Definition at line 9778 of file item.cpp.

9779{
9780 if( !type->artifact ) {
9781 return false;
9782 }
9783 const std::vector<art_effect_passive> &ec = type->artifact->effects_carried;
9784 if( std::find( ec.begin(), ec.end(), effect ) != ec.end() ) {
9785 return true;
9786 }
9787 for( const item *i : contents.all_items_top() ) {
9788 if( i->has_effect_when_carried( effect ) ) {
9789 return true;
9790 }
9791 }
9792 return false;
9793}
Definition: effect.h:161
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
cata::value_ptr< islot_artifact > artifact
Definition: itype.h:866

References item_contents::all_items_top(), itype::artifact, contents, detail::find(), and type.

Referenced by Character::hardcoded_effects(), and Character::has_artifact_with().

◆ has_effect_when_wielded()

bool item::has_effect_when_wielded ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is wielded?

Definition at line 9760 of file item.cpp.

9761{
9762 if( !type->artifact ) {
9763 return false;
9764 }
9765 const std::vector<art_effect_passive> &ew = type->artifact->effects_wielded;
9766 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9767}

References itype::artifact, detail::find(), and type.

Referenced by Character::hardcoded_effects().

◆ has_effect_when_worn()

bool item::has_effect_when_worn ( art_effect_passive  effect) const

Does the item provide the artifact effect when it is worn?

Definition at line 9769 of file item.cpp.

9770{
9771 if( !type->artifact ) {
9772 return false;
9773 }
9774 const std::vector<art_effect_passive> &ew = type->artifact->effects_worn;
9775 return std::find( ew.begin(), ew.end(), effect ) != ew.end();
9776}

References itype::artifact, detail::find(), and type.

◆ has_explosion_data()

bool item::has_explosion_data ( ) const

Definition at line 6834 of file item.cpp.

6835{
6836 return is_fuel() ? type->fuel->has_explode_data : false;
6837}

References itype::fuel, is_fuel(), and type.

Referenced by vehicle::explode_fuel().

◆ has_fault()

bool item::has_fault ( const fault_id fault) const

Does this item have the specified fault.

Definition at line 5301 of file item.cpp.

5302{
5303 return faults.count( fault );
5304}
Definition: fault.h:29

References faults.

Referenced by install_bionic_actor::can_use(), color_in_inventory(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), ranged::handle_gun_damage(), bionic_sterilize_preset::is_shown(), and tname().

◆ has_flag() [1/2]

bool item::has_flag ( const flag_str_id flag) const

Definition at line 5335 of file item.cpp.

5336{
5337 return has_flag( flag.str() );
5338}

References has_flag(), and string_id< T >::str().

◆ has_flag() [2/2]

bool item::has_flag ( const std::string &  flag) const

Definition at line 5311 of file item.cpp.

5312{
5313 bool ret = false;
5314
5315 if( json_flag::get( f ).inherit() ) {
5316 for( const item *e : is_gun() ? gunmods() : toolmods() ) {
5317 // gunmods fired separately do not contribute to base gun flags
5318 if( !e->is_gun() && e->has_flag( f ) ) {
5319 return true;
5320 }
5321 }
5322 }
5323
5324 // other item type flags
5325 ret = type->has_flag( f );
5326 if( ret ) {
5327 return ret;
5328 }
5329
5330 // now check for item specific flags
5331 ret = has_own_flag( f );
5332 return ret;
5333}
bool has_flag(const std::string &flag) const
Definition: itype.cpp:146

References json_flag::get(), gunmods(), itype::has_flag(), has_own_flag(), is_gun(), cata::hash64_detail::ret, toolmods(), and type.

Referenced by Character::activate_bionic(), map::add_item(), map::add_item_or_charges(), monexamine::add_leash(), Character::all_items_with_flag(), Character::allergy_type(), npc::alt_attack(), ammo_consume(), ammo_remaining(), ammo_required(), ammo_set(), amount_of_internal(), Character::armor_absorb(), armor_fit_info(), armor_info(), iexamine::autodoc(), autodoc_internal(), basic_info(), mattack::bio_op_disarm(), iuse::blech(), Character::block_hit(), blocking_ability(), Character::burn_fuel(), butcher_time_to_cut(), butchery_drops_harvest(), calc_rot(), iuse::camera(), item_funcs::can_be_unloaded(), Character::can_consume(), can_do_activity_there(), Character::can_eat(), Character::can_feed_furnace_with(), behavior::character_oracle_t::can_make_fire(), repair_item_actor::can_repair_target(), can_revive(), Character::can_swap(), Character::can_takeoff(), Character::can_unwield(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), cast_spell(), check_litcig(), anonymous_namespace{armor_layers.cpp}::clothing_flags_description(), anonymous_namespace{armor_layers.cpp}::clothing_layer(), color_in_inventory(), combat_info(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), Character::compute_effective_nutrients(), Character::compute_nutrient_range(), conductive(), consider_butchery(), Character::consume_charges(), game_menus::inv::consume_drink(), Character::consume_effects(), game_menus::inv::consume_food(), Character::consume_med(), Character::consume_remote_fuel(), vehicle::consumption_per_hour(), corpse_volume(), activity_handlers::cracking_do_turn(), recipe::create_byproducts(), Single_item_creator::create_single(), iexamine::cvdmachine(), cycle_action(), damage_melee(), repair_item_actor::default_action(), iexamine::dimensional_portal(), display_name(), aim_activity_actor::do_turn(), draw_bionics_titlebar(), game::dump_stats(), durability_indicator(), Character::eat(), einkpc_download_memory_card(), iuse::einktabletpc(), emit_radio_signal(), final_info(), character_funcs::find_ammo_helper(), find_auto_consume(), find_food_heater(), Character::find_remote_fuel(), findBestGasDiscount(), ranged::fire_gun(), activity_handlers::fish_do_turn(), character_funcs::fmt_wielded_weapon(), food_info(), inventory::form_from_map(), Character::fun_for(), activity_handlers::game_do_turn(), character_funcs::get_book_fun_for(), activatable_inventory_preset::get_denial(), bionic_sterilize_preset::get_denial(), get_encumber_when_containing(), ranged::get_fastest_sight(), Character::get_fuel_available(), get_layer(), zone_manager::get_near_zone_type_for_item(), get_sizing(), ranged::get_str_draw_penalty(), getlight_emit(), give_item_to(), goes_bad(), gun_info(), iuse::gun_repair(), gun_type(), gunmod_info(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), ranged::handle_gun_damage(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), has_flag(), Character::has_item_with_flag(), Character::head_cloth_encumbrance(), iuse_transform::info(), inherit_flags(), npc_trading::init_buying(), init_memory_card_with_random_stuff(), target_ui::init_window_and_input(), monexamine::insert_battery(), is_ammo_belt(), is_armor(), is_corpse(), is_dangerous(), advanced_inventory_pane::is_filtered(), is_filthy(), is_firearm(), character_funcs::is_fun_to_read(), is_gunmod_compatible(), is_irremovable(), vehicle::is_perpetual_type(), is_pet_armor(), is_power_armor(), is_reloadable(), is_salvageable(), bionic_uninstall_preset::is_shown(), is_two_handed(), is_unarmed_weapon(), ma_requirements::is_valid_character(), ma_requirements::is_valid_weapon(), is_worn_only_with(), item(), Character::item_reload_cost(), mdeath::jabberwock(), layer_item(), magazine_info(), item_action_generator::map_actions_to_items(), Character::meets_stat_requirements(), Character::melee_attack(), melee_skill(), Character::melee_special_effects(), npc_ai::melee_value(), mine_activity(), Item_modifier::modify(), Character::modify_morale(), avatar_action::move(), game_menus::inv::multiwash(), Character::mutation_effect(), iexamine::nanofab(), needs_processing(), iuse::note_bionics(), on_wear(), on_wield(), iuse::pack_cbm(), Character::passive_power_gen(), monexamine::pet_menu(), avatar_action::plthrow(), iuse::poison(), item_category::priority_zone(), process_extinguish(), process_internal(), Character::process_items(), process_litcig(), process_tool(), process_UPS(), process_vehicle_items(), vehicle_part::properties_to_item(), mattack::pull_metal_weapon(), activity_handlers::pulp_do_turn(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), iuse::radiocontrol(), rate_food(), rcdrive(), reach_range(), ready_to_revive(), reinforceable(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), remove_ammo(), remove_radio_mod(), repair_item_actor::repair(), repaired_with(), game::revive_corpse(), iexamine::safe(), character_funcs::select_ammo(), set_relative_rot(), player_morale::set_worn(), sight_dispersion(), iexamine::sign(), smoker_load_food(), map::spawn_item(), activity_handlers::spellcasting_finish(), activity_handlers::start_fire_do_turn(), starting_clothes(), starting_inv(), ranged::str_draw_damage_modifier(), ranged::str_draw_dispersion_modifier(), ranged::str_draw_range_modifier(), ranged::throw_item(), tname(), tool_info(), iuse::toolmod_attach(), iuse::towel_common(), type_name(), Character::unarmed_attack(), units_remaining(), avatar_funcs::unload_item(), charger_tile::update_internal(), iuse_transform::use(), set_transform_iuse::use(), unpack_actor::use(), cast_spell_actor::use(), Character::use_charges(), iexamine::use_furn_fake_item(), avatar_action::use_item(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), volume(), martialart::weapon_valid(), npc::wear_if_wanted(), Character::wear_item(), iuse::weather_tool(), weight(), weather_effect::wet_player(), npc::will_accept_from_player(), and Character::will_eat().

◆ has_infinite_charges()

bool item::has_infinite_charges ( ) const

Definition at line 9982 of file item.cpp.

9983{
9984 return charges == INFINITE_CHARGES;
9985}

References charges, and INFINITE_CHARGES.

Referenced by display_name(), liquid_handler::get_liquid_target(), mod_charges(), and Character::will_eat().

◆ has_label()

bool item::has_label ( ) const

Returns true if item has "item_label" itemvar.

Definition at line 9968 of file item.cpp.

9969{
9970 return has_var( "item_label" );
9971}

References has_var().

Referenced by label().

◆ has_own_flag()

bool item::has_own_flag ( const std::string &  flag) const

Checks whether item itself has given flag (doesn't check item type or gunmods).

Essentially get_flags().count(f). Works faster than has_flag

Definition at line 5306 of file item.cpp.

5307{
5308 return item_tags.count( f );
5309}
size_type count(const T &t) const
Definition: flat_set.h:141

References cata::flat_set< T, Compare, Data >::count(), and item_tags.

Referenced by Character::can_eat(), Character::can_wear(), color_in_inventory(), final_info(), has_clothing_mod(), has_flag(), mod_last_rot_check(), on_drop(), tname(), update_clothing_mod_val(), and sew_advanced_actor::use().

◆ has_property()

bool item::has_property ( const std::string &  prop) const

Definition at line 5366 of file item.cpp.

5367{
5368 return type->properties.find( prop ) != type->properties.end();
5369}

References itype::properties, and type.

Referenced by iuse::capture_monster_act(), and ranged::throw_item().

◆ has_rotten_away()

bool item::has_rotten_away ( ) const

Whether the item has enough rot that it should get removed.

Regular shelf life perishable foods rot away completely at 2x shelf life. Corpses last 10 days

Returns
true if the item has enough rot to be removed, false otherwise.

Definition at line 8803 of file item.cpp.

8804{
8805 if( is_corpse() && !can_revive() ) {
8806 return get_rot() > 10_days;
8807 } else {
8808 return is_food() && get_relative_rot() > 2.0;
8809 }
8810}
time_duration get_rot() const
Definition: item.h:861

References can_revive(), get_relative_rot(), get_rot(), is_corpse(), and is_food().

Referenced by process_rot().

◆ has_technique()

bool item::has_technique ( const matec_id tech) const

Whether the item supports a specific martial art technique (either through its type, or through its individual techniques).

Definition at line 5447 of file item.cpp.

5448{
5449 return type->techniques.count( tech ) > 0 || techniques.count( tech ) > 0;
5450}

References techniques, itype::techniques, and type.

Referenced by blocking_ability(), effective_dps(), character_martial_arts::has_technique(), and mdeath::jabberwock().

◆ has_tools_to_continue()

bool item::has_tools_to_continue ( ) const

Definition at line 10127 of file item.cpp.

10128{
10129 assert( craft_data_ );
10130 return craft_data_->tools_to_continue;
10131}

References craft_data_.

◆ has_use()

bool item::has_use ( ) const

Returns true if the item has any use function.

Definition at line 7951 of file item.cpp.

7952{
7953 return type->has_use();
7954}
bool has_use() const
Definition: itype.cpp:141

References itype::has_use(), and type.

◆ has_var()

◆ ideal_ranged_dps()

double item::ideal_ranged_dps ( const Character who,
gun_mode mode 
) const

Definition at line 2072 of file npcmove.cpp.

2073{
2074 if( !is_gun() ) {
2075 return 0;
2076 }
2078 if( ammo_current() ) {
2079 itype_id ammo = ammo_current();
2080 gun_damage.add( ammo->ammo->damage );
2081 } else if( ammo_default() ) {
2082 itype_id ammo = ammo_default();
2083 gun_damage.add( ammo->ammo->damage );
2084 }
2085 float damage_factor = gun_damage.total_damage();
2086 damage_factor *= mode.qty;
2087
2088 int move_cost = ranged::time_to_attack( who, *this, item_location() );
2089 if( ammo_remaining() == 0 ) {
2090 int reload_cost = get_reload_time() + who.encumb( bp_hand_l ) + who.encumb( bp_hand_r );
2091 // HACK: Doesn't check how much ammo they'll actually get from the reload. Because we don't know.
2092 // DPS is less impacted the larger the magazine being swapped.
2093 reload_cost /= magazine_integral() ? 1 : ammo_capacity() / mode.qty;
2094 move_cost += reload_cost;
2095 }
2096 std::vector<ranged::aim_type> aim_types = ranged::get_aim_types( who, *this );
2097 auto regular = std::find_if( aim_types.begin(),
2098 aim_types.end(), []( ranged::aim_type at ) {
2099 return at.action == std::string( "AIMED_SHOT" );
2100 } );
2101 if( regular == aim_types.end() ) {
2102 debugmsg( "Could not find REGULAR aim type for gun %s", tname() );
2103 return 0;
2104 }
2105 move_cost += ranged::gun_engagement_moves( who, *this, ( *regular ).threshold );
2106
2107 double dps = damage_factor / ( move_cost / 100.0f );
2108
2109 return dps;
2110}
static int move_cost(const item &it, const tripoint &src, const tripoint &dest)
int qty
burst size for is_gun() firearms, or melee range for is_melee() weapons
Definition: gun_mode.h:21
A lightweight handle to an item independent of it's location Unlike a raw pointer can be (de-)seriali...
Definition: item_location.h:23
int get_reload_time() const
Returns the reload time of the gun.
Definition: item.cpp:6536
void regular(const queued_explosion &qe)
Definition: explosion.cpp:1466
int time_to_attack(const Character &p, const item &firing, const item_location loc)
Calculates time taken to fire gun.
Definition: ranged.cpp:1737
void add(const damage_instance &added_di)
Definition: damage.cpp:93

References damage_instance::add(), itype::ammo, ammo_capacity(), ammo_current(), ammo_default(), ammo_remaining(), bp_hand_l, bp_hand_r, debugmsg, dps(), Character::encumb(), ranged::get_aim_types(), get_reload_time(), gun_damage(), ranged::gun_engagement_moves(), is_gun(), magazine_integral(), move_cost(), gun_mode::qty, explosion_handler::explosion_funcs::regular(), ranged::time_to_attack(), tname(), and damage_instance::total_damage().

Referenced by npc::check_or_use_weapon_cbm(), and npc_ai::gun_value().

◆ in_container()

item item::in_container ( const itype_id container_type) const

Definition at line 849 of file item.cpp.

850{
851 if( !cont.is_null() ) {
852 item ret( cont, birthday() );
853 ret.put_in( *this );
854 if( made_of( LIQUID ) && ret.is_container() ) {
855 // Note: we can't use any of the normal container functions as they check the
856 // container being suitable (seals, watertight etc.)
857 ret.contents.back().charges = charges_per_volume( ret.get_container_capacity() );
858 }
859
860 ret.invlet = invlet;
861 return ret;
862 } else {
863 return *this;
864 }
865}
char invlet
Definition: item.h:2240

References birthday(), charges_per_volume(), invlet, string_id< T >::is_null(), LIQUID, made_of(), and cata::hash64_detail::ret.

Referenced by in_its_container().

◆ in_its_container()

item item::in_its_container ( ) const

Returns this item into its default container.

If it does not have a default container, returns this. It's intended to be used like

newitem = newitem.in_its_container();

Definition at line 844 of file item.cpp.

845{
846 return in_container( type->default_container.value_or( itype_id::NULL_ID() ) );
847}
item in_container(const itype_id &container_type) const
Definition: item.cpp:849
std::optional< itype_id > default_container
Definition: itype.h:912

References itype::default_container, in_container(), string_id< itype >::NULL_ID(), and type.

Referenced by defense_game::caravan(), crafting::complete_disassemble(), Single_item_creator::create_single(), map::spawn_an_item(), starting_inv(), and debug_menu::wishitem().

◆ inc_damage() [1/2]

bool item::inc_damage ( )

same as other inc_damage, but uses DT_NULL as damage type.

Definition at line 6266 of file item.cpp.

6267{
6268 return inc_damage( DT_NULL );
6269}
bool inc_damage()
same as other inc_damage, but uses DT_NULL as damage type.
Definition: item.cpp:6266

References DT_NULL, and inc_damage().

Referenced by inc_damage(), and process_blackpowder_fouling().

◆ inc_damage() [2/2]

bool item::inc_damage ( damage_type  dt)

Increment item damage by itype::damage_scale constrained by max_damage.

Parameters
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6261 of file item.cpp.

6262{
6263 return mod_damage( itype::damage_scale, dt );
6264}
bool mod_damage(int qty, damage_type dt)
Apply damage to const itemrained by min_damage and max_damage.
Definition: item.cpp:6234
static constexpr int damage_scale
Definition: itype.h:1008

References itype::damage_scale, and mod_damage().

Referenced by iuse::blood_draw(), damage_item(), iuse::firecracker_pack_act(), activity_handlers::gunmod_add_finish(), ranged::handle_gun_damage(), Character::handle_melee_wear(), activity_handlers::lockpicking_finish(), and vehicle::operate_scoop().

◆ info() [1/4]

std::vector< iteminfo > item::info ( ) const

Return all the information about the item and its type as a vector.

This includes the different properties of the itype (if they are visible to the player).

Parameters
partscontrols which parts of the iteminfo to return.
batchThe batch crafting number to multiply data by
Returns
The properties (encapsulated into iteminfo) are added to this vector, the vector can be used to compare them to properties of another item.

Definition at line 3974 of file item.cpp.

3975{
3977}
static const iteminfo_query no_conditions

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

Referenced by advanced_inventory::action_examine(), ammo_info(), animal_armor_info(), armor_fit_info(), armor_info(), armor_protection_info(), basic_info(), battery_info(), bionic_info(), book_info(), combat_info(), game_menus::inv::compare(), component_info(), container_info(), contents_info(), disassembly_info(), final_info(), food_info(), gun_info(), gunmod_info(), info(), info_string(), game::list_items(), magazine_info(), med_info(), qualities_info(), wish_item_callback::refresh(), repair_info(), examine_item_menu::run(), trading_window::show_item_data(), and tool_info().

◆ info() [2/4]

std::vector< iteminfo > item::info ( const iteminfo_query parts,
int  batch,
temperature_flag  temperature 
) const

Definition at line 3989 of file item.cpp.

3991{
3992 const bool debug = g != nullptr && debug_mode;
3993
3994 // TODO: Use reference properly
3995 const iteminfo_query *parts = &parts_ref;
3996 std::vector<iteminfo> info;
3997
3998 if( !is_null() ) {
3999 basic_info( info, parts, batch, debug );
4000 }
4001
4002 const item *med_item = nullptr;
4003 if( is_medication() ) {
4004 med_item = this;
4005 } else if( is_med_container() ) {
4006 med_item = &contents.front();
4007 }
4008 if( med_item != nullptr ) {
4009 med_info( med_item, info, parts, batch, debug );
4010 }
4011
4012 if( const item *food_item = get_food() ) {
4013 food_info( food_item, info, parts, batch, debug, temperature );
4014 }
4015
4016 container_info( info, parts, batch, debug );
4017 contents_info( info, parts, batch, debug );
4018 combat_info( info, parts, batch, debug );
4019
4020 magazine_info( info, parts, batch, debug );
4021 ammo_info( info, parts, batch, debug );
4022
4023 const item *gun = nullptr;
4024 if( is_gun() ) {
4025 gun = this;
4026 const gun_mode aux = gun_current_mode();
4027 // if we have an active auxiliary gunmod display stats for this instead
4028 if( aux && aux->is_gunmod() && aux->is_gun() &&
4030 gun = &*aux;
4031 info.emplace_back( "DESCRIPTION",
4032 string_format( _( "Stats of the active <info>gunmod (%s)</info> "
4033 "are shown." ), gun->tname() ) );
4034 }
4035 }
4036 if( gun != nullptr ) {
4037 gun_info( gun, info, parts, batch, debug );
4038 }
4039
4040 gunmod_info( info, parts, batch, debug );
4041 armor_info( info, parts, batch, debug );
4042 animal_armor_info( info, parts, batch, debug );
4043 book_info( info, parts, batch, debug );
4044 battery_info( info, parts, batch, debug );
4045 tool_info( info, parts, batch, debug );
4046 component_info( info, parts, batch, debug );
4047 qualities_info( info, parts, batch, debug );
4048
4049 // Uses for item (bandaging quality, holster capacity, grenade activation)
4051 for( const std::pair<const std::string, use_function> &method : type->use_methods ) {
4053 method.second.dump_info( *this, info );
4054 }
4055 }
4056
4057 repair_info( info, parts, batch, debug );
4058 disassembly_info( info, parts, batch, debug );
4059
4060 final_info( info, parts_ref, batch, debug );
4061
4062 if( !info.empty() && info.back().sName == "--" ) {
4063 info.pop_back();
4064 }
4065
4066 return info;
4067}
void gunmod_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2383
gun_mode gun_current_mode() const
Get the current mode for this gun (or an invalid mode if item is not a gun)
Definition: item.cpp:7906
void contents_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3546
void animal_armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2718
void med_info(const item *med_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1644
void disassembly_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3177
void combat_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3401
bool is_med_container() const
Definition: item.cpp:6623
void qualities_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3231
void gun_info(const item *mod, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2020
void component_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3132
void repair_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3156
void magazine_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1884
void food_info(const item *food_item, std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug, temperature_flag temperature) const
Definition: item.cpp:1673
void armor_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2535
void battery_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3065
void ammo_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1907
void basic_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:1461
void final_info(std::vector< iteminfo > &info, const iteminfo_query &parts, int batch, bool debug) const
Definition: item.cpp:3629
void book_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:2900
void tool_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3084
void container_info(std::vector< iteminfo > &info, const iteminfo_query *parts, int batch, bool debug) const
Definition: item.cpp:3037
@ DESCRIPTION_AUX_GUNMOD_HEADER

References _, ammo_info(), animal_armor_info(), armor_info(), basic_info(), battery_info(), book_info(), combat_info(), component_info(), container_info(), contents, contents_info(), debug, debug_mode, DESCRIPTION_AUX_GUNMOD_HEADER, DESCRIPTION_USE_METHODS, disassembly_info(), final_info(), food_info(), item_contents::front(), g, get_food(), gun_current_mode(), gun_info(), gunmod_info(), info(), insert_separation_line(), is_gun(), is_gunmod(), is_med_container(), is_medication(), is_null(), magazine_info(), med_info(), qualities_info(), repair_info(), string_format(), iteminfo_query::test(), tname(), tool_info(), type, and itype::use_methods.

◆ info() [3/4]

std::vector< iteminfo > item::info ( int  batch) const

Definition at line 3979 of file item.cpp.

References info(), iteminfo_query::no_conditions, and TEMP_NORMAL.

◆ info() [4/4]

std::vector< iteminfo > item::info ( temperature_flag  temperature) const

Definition at line 3984 of file item.cpp.

3985{
3986 return info( iteminfo_query::all, 1, temperature );
3987}
static const iteminfo_query all

References iteminfo_query::all, and info().

◆ info_string() [1/2]

std::string item::info_string ( ) const

As info, but as a string rather than a vector of properties.

Definition at line 4069 of file item.cpp.

4070{
4071 return info_string( iteminfo_query::all, 1 );
4072}

References iteminfo_query::all, and info_string().

Referenced by battery_info(), colorized_item_description(), draw_caravan_items(), and info_string().

◆ info_string() [2/2]

std::string item::info_string ( const iteminfo_query parts,
int  batch = 1,
temperature_flag  temperature = temperature_flag::TEMP_NORMAL 
) const

Definition at line 4074 of file item.cpp.

4076{
4077 std::vector<iteminfo> item_info = info( parts, batch, temperature );
4078 return format_item_info( item_info, {} );
4079}
std::string format_item_info(const std::vector< iteminfo > &item_display, const std::vector< iteminfo > &item_compare)
Definition: output.cpp:854

References format_item_info(), and info().

◆ inherit_flags() [1/2]

void item::inherit_flags ( const item parent,
const recipe making 
)

Inherit applicable flags from the given parent item.

Parameters
parentItem to inherit from

Definition at line 984 of file crafting.cpp.

985{
986 // default behavior is to resize the clothing, which happens elsewhere
987 if( making.has_flag( flag_NO_RESIZE ) ) {
988 //If item is crafted from poor-fit components, the result is poorly fitted too
989 if( parent.has_flag( flag_VARSIZE ) ) {
991 }
992 //If item is crafted from perfect-fit components, the result is perfectly fitted too
993 if( parent.has_flag( flag_FIT ) ) {
995 }
996 }
997 for( const std::string &f : parent.item_tags ) {
998 if( json_flag::get( f ).craft_inherit() ) {
999 set_flag( f );
1000 }
1001 }
1002 for( const std::string &f : parent.type->get_flags() ) {
1003 if( json_flag::get( f ).craft_inherit() ) {
1004 set_flag( f );
1005 }
1006 }
1007 if( parent.has_flag( flag_HIDDEN_POISON ) ) {
1008 poison = parent.poison;
1009 }
1010}
int poison
Definition: item.h:2208
bool has_flag(const std::string &flag_name) const
Definition: recipe.cpp:92
static const std::string flag_NO_RESIZE("NO_RESIZE")
static const std::string flag_HIDDEN_POISON("HIDDEN_POISON")
static const std::string flag_FIT("FIT")
static const std::string flag_VARSIZE("VARSIZE")

References flag_FIT(), flag_HIDDEN_POISON(), flag_NO_RESIZE(), flag_VARSIZE(), json_flag::get(), itype::get_flags(), has_flag(), recipe::has_flag(), item_tags, poison, set_flag(), type, and unset_flag().

Referenced by complete_craft(), and inherit_flags().

◆ inherit_flags() [2/2]

void item::inherit_flags ( const std::list< item > &  parents,
const recipe making 
)

Inherit applicable flags from the given list of parent items.

Parameters
parentsItems to inherit from

Definition at line 1012 of file crafting.cpp.

1013{
1014 for( const item &parent : parents ) {
1015 inherit_flags( parent, making );
1016 }
1017}
void inherit_flags(const item &parent, const recipe &making)
Inherit applicable flags from the given parent item.
Definition: crafting.cpp:984
std::vector< item * > parents(const item &it)
Returns vector of parent containers (if any) starting with the innermost.
Definition: visitable.cpp:73

References inherit_flags(), and visitable< item >::parents().

◆ io()

template<typename Archive >
void item::io ( Archive &  archive)

Definition at line 2188 of file savegame_json.cpp.

2189{
2190
2191 itype_id orig; // original ID as loaded from JSON
2192 const auto load_type = [&]( const std::string & id ) {
2193 orig = itype_id( id );
2194 convert( item_controller->migrate_id( orig ) );
2195 };
2196
2197 const auto load_curammo = [this]( const std::string & id ) {
2198 curammo = &*item_controller->migrate_id( itype_id( id ) );
2199 };
2200 const auto load_corpse = [this]( const std::string & id ) {
2201 if( itype_id( id ).is_null() ) {
2202 // backwards compatibility, nullptr should not be stored at all
2203 corpse = nullptr;
2204 } else {
2205 corpse = &mtype_id( id ).obj();
2206 }
2207 };
2208 archive.template io<const itype>( "typeid", type, load_type, []( const itype & i ) {
2209 return i.get_id().str();
2210 }, io::required_tag() );
2211
2212 // normalize legacy saves to always have charges >= 0
2213 archive.io( "charges", charges, 0 );
2214 charges = std::max( charges, 0 );
2215
2216 archive.io( "energy", energy, 0_J );
2217
2218 archive.io( "burnt", burnt, 0 );
2219 archive.io( "poison", poison, 0 );
2220 archive.io( "frequency", frequency, 0 );
2221 archive.io( "snip_id", snip_id, snippet_id::NULL_ID() );
2222 // NB! field is named `irridation` in legacy files
2223 archive.io( "irridation", irradiation, 0 );
2224 archive.io( "bday", bday, calendar::start_of_cataclysm );
2225 archive.io( "mission_id", mission_id, -1 );
2226 archive.io( "player_id", player_id, -1 );
2227 archive.io( "item_vars", item_vars, io::empty_default_tag() );
2228 // TODO: change default to empty string
2229 archive.io( "name", corpse_name, std::string() );
2230 archive.io( "owner", owner, owner.NULL_ID() );
2231 archive.io( "old_owner", old_owner, old_owner.NULL_ID() );
2232 archive.io( "invlet", invlet, '\0' );
2233 archive.io( "damaged", damage_, 0 );
2234 archive.io( "active", active, false );
2235 archive.io( "is_favorite", is_favorite, false );
2236 archive.io( "item_counter", item_counter, static_cast<decltype( item_counter )>( 0 ) );
2237 archive.io( "rot", rot, 0_turns );
2238 archive.io( "last_rot_check", last_rot_check, calendar::start_of_cataclysm );
2239 archive.io( "techniques", techniques, io::empty_default_tag() );
2240 archive.io( "faults", faults, io::empty_default_tag() );
2241 archive.io( "item_tags", item_tags, io::empty_default_tag() );
2242 archive.io( "components", components, io::empty_default_tag() );
2243 archive.io( "recipe_charges", recipe_charges, 1 );
2244 archive.template io<const itype>( "curammo", curammo, load_curammo,
2245 []( const itype & i ) {
2246 return i.get_id().str();
2247 } );
2248 archive.template io<const mtype>( "corpse", corpse, load_corpse,
2249 []( const mtype & i ) {
2250 return i.id.str();
2251 } );
2252 archive.io( "craft_data", craft_data_, decltype( craft_data_ )() );
2253 archive.io( "light", light.luminance, nolight.luminance );
2254 archive.io( "light_width", light.width, nolight.width );
2255 archive.io( "light_dir", light.direction, nolight.direction );
2256
2257 static const cata::value_ptr<relic> null_relic_ptr = nullptr;
2258 archive.io( "relic_data", relic_data, null_relic_ptr );
2259
2260 archive.io( "drop_token", drop_token, decltype( drop_token )() );
2261
2262 item_controller->migrate_item( orig, *this );
2263
2264 if( !Archive::is_input::value ) {
2265 return;
2266 }
2267 /* Loading has finished, following code is to ensure consistency and fixes bugs in saves. */
2268
2270
2271 double float_damage = 0;
2272 if( archive.read( "damage", float_damage ) ) {
2273 damage_ = std::min( std::max( min_damage(),
2274 static_cast<int>( float_damage * itype::damage_scale ) ),
2275 max_damage() );
2276 }
2277
2278 int note = 0;
2279 const bool note_read = archive.read( "note", note );
2280
2281 // Old saves used to only contain one of those values (stored under "poison"), it would be
2282 // loaded into a union of those members. Now they are separate members and must be set separately.
2283 if( poison != 0 && note == 0 && !type->snippet_category.empty() ) {
2284 std::swap( note, poison );
2285 }
2286 if( poison != 0 && frequency == 0 && ( typeId() == itype_radio_on || typeId() == itype_radio ) ) {
2288 }
2289 if( poison != 0 && irradiation == 0 && typeId() == itype_rad_badge ) {
2291 }
2292
2293 // erase all invalid flags (not defined in flags.json), display warning about invalid flags
2294 erase_if( item_tags, [&]( const std::string & f ) {
2295 if( !json_flag::get( f ).id.is_valid() ) {
2296 debugmsg( "item of type '%s' was loaded with undefined flag '%s'.", typeId().c_str(), f );
2297 return true;
2298 } else {
2299 return false;
2300 }
2301 } );
2302
2303 if( note_read ) {
2305 } else {
2306 std::optional<std::string> snip;
2307 if( archive.read( "snippet_id", snip ) && snip ) {
2308 snip_id = snippet_id( snip.value() );
2309 }
2310 }
2311
2312 // Compatibility for item type changes: for example soap changed from being a generic item
2313 // (item::charges -1 or 0 or anything else) to comestible (and thereby counted by charges),
2314 // old saves still have invalid charges, this fixes the charges value to the default charges.
2315 if( count_by_charges() && charges <= 0 ) {
2317 }
2318 if( is_food() ) {
2319 active = true;
2320 }
2321 if( !active && item_tags.count( "WET" ) > 0 ) {
2322 // Some wet items from legacy saves may be inactive
2323 active = true;
2324 }
2325 std::string mode;
2326 if( archive.read( "mode", mode ) ) {
2327 // only for backward compatibility (nowadays mode is stored in item_vars)
2328 gun_set_mode( gun_mode_id( mode ) );
2329 }
2330
2331 // Books without any chapters don't need to store a remaining-chapters
2332 // counter, it will always be 0 and it prevents proper stacking.
2333 if( get_chapters() == 0 ) {
2334 for( auto it = item_vars.begin(); it != item_vars.end(); ) {
2335 if( it->first.compare( 0, 19, "remaining-chapters-" ) == 0 ) {
2336 item_vars.erase( it++ );
2337 } else {
2338 ++it;
2339 }
2340 }
2341 }
2342
2343 // Remove stored translated gerund in favor of storing the inscription tool type
2344 item_vars.erase( "item_label_type" );
2345 item_vars.erase( "item_note_type" );
2346
2347 // Activate corpses from old saves
2348 if( is_corpse() && !active ) {
2349 active = true;
2350 }
2351
2352 if( charges != 0 && !type->can_have_charges() ) {
2353 // Types that are known to have charges, but should not have them.
2354 // We fix it here, but it's expected from bugged saves and does not require a message.
2355 if( charge_removal_blacklist::get().count( type->get_id() ) == 0 ) {
2356 debugmsg( "Item %s was loaded with charges, but can not have any!", type->get_id() );
2357 }
2358 charges = 0;
2359 }
2360
2361 // Relic check. Kinda late, but that's how relics have to be
2362 if( relic_data ) {
2363 relic_data->check();
2364 }
2365}
bool erase_if(Col &set, Pred predicate)
Erases elements from a set that match given predicate function.
Definition: cata_utility.h:237
int player_id
Definition: item.h:2214
int mission_id
Definition: item.h:2213
int frequency
Definition: item.h:2209
int recipe_charges
Definition: item.h:2206
snippet_id migrate_hash_to_id(int hash)
Used only for legacy compatibility.
light_emission nolight
Definition: item.cpp:315
void swap(colony< element_type, element_allocator_type, element_skipfield_type > &a, colony< element_type, element_allocator_type, element_skipfield_type > &b) COLONY_NOEXCEPT_SWAP(element_allocator_type)
Swaps colony A's contents with that of colony B.
Definition: colony.h:3496
const std::set< itype_id > & get()
static void load_legacy_craft_data(io::JsonObjectInputArchive &archive, T &value)
static const itype_id itype_radio("radio")
static const itype_id itype_radio_on("radio_on")
static const itype_id itype_rad_badge("rad_badge")
Tag that indicates the value of the io is some kind of container and its default value is to be empty...
Definition: cata_io.h:105
Tag that indicates the value is required and must exists in the JSON data.
Definition: cata_io.h:110
bool can_have_charges() const
Definition: itype.cpp:219
mtype_id id
Definition: mtype.h:240
string_id< translation > snippet_id
Definition: type_id.h:205

References active, bday, burnt, itype::can_have_charges(), charges, components, convert(), corpse, corpse_name, count(), cata::flat_set< T, Compare, Data >::count(), count_by_charges(), craft_data_, curammo, damage_, itype::damage_scale, debugmsg, light_emission::direction, energy, erase_if(), faults, frequency, charge_removal_blacklist::get(), json_flag::get(), get_chapters(), itype::get_id(), gun_set_mode(), base_camps::id, itype::id, invlet, irradiation, is_corpse(), is_favorite, is_food(), item(), item_controller, item_counter, item_tags, item_vars, itype_id, itype_rad_badge, itype_radio, itype_radio_on, last_rot_check, light, load_legacy_craft_data(), light_emission::luminance, max_damage(), snippet_library::migrate_hash_to_id(), min_damage(), mission_id, mtype_id, nolight, string_id< translation >::NULL_ID(), string_id< T >::NULL_ID(), old_owner, owner, player_id, poison, recipe_charges, relic_data, snip_id, SNIPPET, itype::snippet_category, calendar::start_of_cataclysm, string_id< T >::str(), cata::swap(), techniques, type, typeId(), and light_emission::width.

Referenced by deserialize(), and serialize().

◆ is_ammo()

◆ is_ammo_belt()

bool item::is_ammo_belt ( ) const

Definition at line 6575 of file item.cpp.

6576{
6577 return is_magazine() && has_flag( flag_MAG_BELT );
6578}
static const std::string flag_MAG_BELT("MAG_BELT")

References flag_MAG_BELT(), has_flag(), and is_magazine().

Referenced by Character::can_reload(), item_reload_option::item_reload_option(), avatar_action::reload(), reload(), and avatar_funcs::unload_item().

◆ is_ammo_container()

◆ is_armor()

◆ is_artifact()

bool item::is_artifact ( ) const

Definition at line 6976 of file item.cpp.

6977{
6978 return !!type->artifact;
6979}

References itype::artifact, and type.

Referenced by game::add_artifact_dreams(), iuse::artifact(), needs_processing(), and process_artifact().

◆ is_bandolier()

bool item::is_bandolier ( ) const

◆ is_battery()

bool item::is_battery ( ) const

Definition at line 6570 of file item.cpp.

6571{
6572 return !!type->battery;
6573}

References itype::battery, and type.

Referenced by battery_info(), display_name(), energy_remaining(), and mod_energy().

◆ is_bionic()

◆ is_book()

◆ is_brewable()

bool item::is_brewable ( ) const

Definition at line 6611 of file item.cpp.

6612{
6613 return !!type->brewable;
6614}

References itype::brewable, and type.

Referenced by brewing_results(), brewing_time(), final_info(), iexamine::fvat_empty(), and iexamine::fvat_full().

◆ is_bucket()

bool item::is_bucket ( ) const

Definition at line 6742 of file item.cpp.

6743{
6744 // That "preserves" part is a hack:
6745 // Currently all non-empty cans are effectively sealed at all times
6746 // Making them buckets would cause weirdness
6747 return type->container &&
6748 type->container->watertight &&
6749 !type->container->seals &&
6750 !type->container->unseals_into;
6751}

References itype::container, and type.

Referenced by can_unload_liquid(), get_remaining_capacity_for_liquid(), is_bucket_nonempty(), is_container_eligible_for_crafting(), is_funnel_container(), pick_one_up(), and iexamine::tree_maple_tapped().

◆ is_bucket_nonempty()

bool item::is_bucket_nonempty ( ) const

◆ is_comestible()

◆ is_container()

◆ is_container_empty()

◆ is_container_full()

bool item::is_container_full ( bool  allow_bucket = false) const

Whether this item has no more free capacity for its current content.

Parameters
allow_bucketAllow filling non-sealable containers

Definition at line 6850 of file item.cpp.

6851{
6852 if( is_container_empty() ) {
6853 return false;
6854 }
6855 return get_remaining_capacity_for_liquid( contents.front(), allow_bucket ) == 0;
6856}

References contents, item_contents::front(), get_remaining_capacity_for_liquid(), and is_container_empty().

Referenced by is_container_eligible_for_crafting(), is_reloadable_helper(), and avatar_action::reload().

◆ is_corpse()

bool item::is_corpse ( ) const

Whether this is a corpse item.

Corpses always have valid monster type (corpse) associated (get_mtype return a non-null pointer) and have been created with make_corpse.

Definition at line 6628 of file item.cpp.

6629{
6630 return corpse != nullptr && has_flag( flag_CORPSE );
6631}

References corpse, flag_CORPSE(), and has_flag().

Referenced by base_volume(), burn(), activity_handlers::butcher_finish(), calc_rot(), can_revive(), color(), color_in_inventory(), component_info(), zone_manager::get_near_zone_type_for_item(), get_shelf_life(), goes_bad(), has_rotten_away(), io(), made_of(), on_damage(), process_internal(), map::process_items_in_vehicle(), processing_speed(), game::revive_corpse(), tname(), volume(), and weight().

◆ is_craft()

◆ is_dangerous()

bool item::is_dangerous ( ) const

Definition at line 9822 of file item.cpp.

9823{
9824 if( has_flag( flag_DANGEROUS ) ) {
9825 return true;
9826 }
9827
9828 // Note: Item should be dangerous regardless of what type of a container is it
9829 // Visitable interface would skip some options
9830 for( const item *it : contents.all_items_top() ) {
9831 if( it->is_dangerous() ) {
9832 return true;
9833 }
9834 }
9835 return false;
9836}
static const std::string flag_DANGEROUS("DANGEROUS")

References item_contents::all_items_top(), contents, flag_DANGEROUS(), and has_flag().

Referenced by give_item_to(), and npc::value().

◆ is_deployable()

bool item::is_deployable ( ) const

Definition at line 6961 of file item.cpp.

6962{
6963 return type->can_use( "deploy_furn" );
6964}

References itype::can_use(), and type.

Referenced by Character::invoke_item().

◆ is_emissive()

bool item::is_emissive ( ) const

Whether the item emits any light at all.

Definition at line 6956 of file item.cpp.

6957{
6958 return light.luminance > 0 || type->light_emission > 0;
6959}

References light, itype::light_emission, light_emission::luminance, and type.

Referenced by submap::load(), map::update_lum(), submap::update_lum_add(), and submap::update_lum_rem().

◆ is_engine()

bool item::is_engine ( ) const

Definition at line 6758 of file item.cpp.

6759{
6760 return !!type->engine;
6761}

References itype::engine, and type.

Referenced by is_faulty(), and tname().

◆ is_faulty()

bool item::is_faulty ( ) const

Definition at line 6778 of file item.cpp.

6779{
6780 return is_engine() ? !faults.empty() : false;
6781}
bool is_engine() const
Definition: item.cpp:6758

References faults, and is_engine().

Referenced by clear_faults(), and vehicle_part::name().

◆ is_filthy()

bool item::is_filthy ( ) const

Marks the item as filthy, so characters with squeamish trait can't wear it.

Definition at line 10002 of file item.cpp.

10003{
10004 return has_flag( flag_FILTHY ) && ( get_option<bool>( "FILTHY_MORALE" ) ||
10006}
static const std::string flag_FILTHY("FILTHY")
static const trait_id trait_SQUEAMISH("SQUEAMISH")

References flag_FILTHY(), get_avatar(), has_flag(), Character::has_trait(), and trait_SQUEAMISH.

Referenced by Character::can_wear(), color_in_inventory(), crafting::complete_disassemble(), salvage_actor::cut_up(), repair_item_actor::handle_components(), item_category::priority_zone(), activity_handlers::reload_finish(), tname(), avatar_funcs::unload_item(), and heal_actor::use().

◆ is_firearm()

bool item::is_firearm ( ) const

Does it require gunsmithing tools to repair.

Definition at line 6530 of file item.cpp.

6531{
6532 static const std::string primitive_flag( "PRIMITIVE_RANGED_WEAPON" );
6533 return is_gun() && !has_flag( primitive_flag );
6534}

References has_flag(), and is_gun().

Referenced by repair_item_actor::can_repair_target(), iuse::gun_repair(), and repair_inventory_preset::is_shown().

◆ is_food()

◆ is_food_container()

bool item::is_food_container ( ) const

◆ is_fresh()

bool item::is_fresh ( ) const
inline

an item is fresh if it is capable of rotting but still has a long shelf life remaining

Definition at line 840 of file item.h.

840 {
841 return goes_bad() && get_relative_rot() < 0.1;
842 }

Referenced by comestible_inventory_preset::get_freshness(), get_freshness_description(), and tname().

◆ is_fuel()

bool item::is_fuel ( ) const

Definition at line 6768 of file item.cpp.

6769{
6770 return !!type->fuel;
6771}

References itype::fuel, and type.

Referenced by Character::can_fuel_bionic_with(), vehicle_part::consume_energy(), fuel_energy(), fuel_pump_terrain(), and has_explosion_data().

◆ is_funnel_container()

bool item::is_funnel_container ( units::volume bigger_than) const

Funnel related functions.

See weather.cpp for their usage.

Definition at line 6936 of file item.cpp.

6937{
6938 if( !is_bucket() && !is_watertight_container() ) {
6939 return false;
6940 }
6941 // TODO: consider linking funnel to item or -making- it an active item
6942 if( get_container_capacity() <= bigger_than ) {
6943 return false; // skip contents check, performance
6944 }
6945 if(
6946 contents.empty() ||
6950 bigger_than = get_container_capacity();
6951 return true;
6952 }
6953 return false;
6954}
bool is_watertight_container() const
Whether this is a container which can be used to store liquids.
Definition: item.cpp:6732
static const itype_id itype_water_acid_weak("water_acid_weak")
static const itype_id itype_water_acid("water_acid")
static const itype_id itype_water("water")

References contents, item_contents::empty(), item_contents::front(), get_container_capacity(), is_bucket(), is_watertight_container(), itype_water, itype_water_acid, itype_water_acid_weak, and typeId().

◆ is_going_bad()

bool item::is_going_bad ( ) const
inline

an item is about to become rotten when shelf life has nearly elapsed

Definition at line 845 of file item.h.

845 {
846 return get_relative_rot() > 0.9;
847 }

Referenced by get_freshness_description(), comestible_inventory_preset::get_time_left_rounded(), and tname().

◆ is_gun()

bool item::is_gun ( ) const

Can this item be used to perform a ranged attack?

See also
item::is_melee()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6525 of file item.cpp.

6526{
6527 return !!type->gun;
6528}

References itype::gun, and type.

Referenced by vehicle::add_item(), ranged::aim_per_move(), allow_crafting_component(), ammo_capacity(), ammo_consume(), character_funcs::ammo_count_for(), ammo_data(), ammo_effects(), ammo_info(), ammo_remaining(), ammo_required(), ammo_set(), ammo_sort_name(), ammo_types(), ammo_unset(), npc_ai::best_mode_for_range(), can_fire_turret(), avatar_action::can_fire_weapon(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), defense_game::caravan(), casings_handle(), npc::character_danger(), npc::check_or_use_weapon_cbm(), color_in_inventory(), npc::confident_shoot_range(), contents_info(), contextualize_skill(), damage_melee(), display_name(), durability_indicator(), final_info(), character_funcs::find_ammo_helper(), character_funcs::find_reloadables(), fire(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), character_funcs::fmt_wielded_weapon(), npc::form_opinion(), ranged::get_aim_types(), get_covered_body_parts(), get_encumber_when_containing(), get_free_mod_locations(), ranged::get_most_accurate_sight(), get_reload_time(), give_item_to(), gun_all_modes(), gun_cycle_mode(), gun_damage(), gun_dispersion(), gun_get_mode(), gun_get_mode_id(), gun_noise(), gun_range(), gun_recoil(), gun_set_mode(), gun_skill(), gun_type(), gunmod_info(), game::handle_action(), ranged::handle_gun_damage(), has_flag(), Character::i_add(), ideal_ranged_dps(), info(), character_effects::intimidation(), is_firearm(), is_gunmod_compatible(), is_reloadable(), gunmod_inventory_preset::is_shown(), saw_barrel_inventory_preset::is_shown(), saw_stock_inventory_preset::is_shown(), vehicle_part::is_turret(), Character::item_reload_cost(), Character::item_store_cost(), magazine_compatible(), magazine_default(), magazine_integral(), Item_modifier::modify(), item_reload_option::moves(), Character::on_dodge(), on_wield(), parse_tags(), tutorial_game::post_action(), Character::power_rating(), reach_range(), activity_handlers::reload_finish(), remove_ammo(), item_funcs::shots_remaining(), sight_dispersion(), starting_inv(), tname(), game::try_get_right_click_action(), character_funcs::try_wield_contents(), npc::value(), visit_internal(), volume(), weapon_inventory_preset::weapon_inventory_preset(), weight(), and npc::wield_better_weapon().

◆ is_gunmod()

◆ is_gunmod_compatible()

ret_val< bool > item::is_gunmod_compatible ( const item mod) const

Definition at line 7772 of file item.cpp.

7773{
7774 if( !mod.is_gunmod() ) {
7775 debugmsg( "Tried checking compatibility of non-gunmod" );
7777 }
7778 static const gun_type_type pistol_gun_type( translate_marker_context( "gun_type_type", "pistol" ) );
7779 static const skill_id skill_archery( "archery" );
7780 static const std::string bow_hack_str( "bow" );
7781
7782 if( !is_gun() ) {
7783 return ret_val<bool>::make_failure( _( "isn't a weapon" ) );
7784
7785 } else if( is_gunmod() ) {
7786 return ret_val<bool>::make_failure( _( "is a gunmod and cannot be modded" ) );
7787
7788 } else if( gunmod_find( mod.typeId() ) ) {
7789 return ret_val<bool>::make_failure( _( "already has a %s" ), mod.tname( 1 ) );
7790
7791 } else if( !get_mod_locations().count( mod.type->gunmod->location ) ) {
7792 return ret_val<bool>::make_failure( _( "doesn't have a slot for this mod" ) );
7793
7794 } else if( get_free_mod_locations( mod.type->gunmod->location ) <= 0 ) {
7795 return ret_val<bool>::make_failure( _( "doesn't have enough room for another %s mod" ),
7796 mod.type->gunmod->location.name() );
7797
7798 // TODO: Get rid of the "archery"->"bow" hack
7799 } else if( !mod.type->gunmod->usable.count( gun_type() ) &&
7800 !mod.type->gunmod->usable.count( typeId().str() ) &&
7801 !( gun_skill() == skill_archery && mod.type->gunmod->usable.count( bow_hack_str ) > 0 ) ) {
7802 return ret_val<bool>::make_failure( _( "cannot have a %s" ), mod.tname() );
7803
7804 } else if( typeId() == itype_hand_crossbow &&
7805 !mod.type->gunmod->usable.count( pistol_gun_type ) ) {
7806 return ret_val<bool>::make_failure( _( "isn't big enough to use that mod" ) );
7807
7808 } else if( mod.type->gunmod->location.str() == "underbarrel" &&
7810 return ret_val<bool>::make_failure( _( "can only accept small mods on that slot" ) );
7811
7812 } else if( !mod.type->mod->acceptable_ammo.empty() ) {
7813 bool compat_ammo = false;
7814 for( const ammotype &at : mod.type->mod->acceptable_ammo ) {
7815 if( ammo_types( false ).count( at ) ) {
7816 compat_ammo = true;
7817 }
7818 }
7819 if( !compat_ammo ) {
7821 _( "%1$s cannot be used on item with no compatible ammo types" ), mod.tname( 1 ) );
7822 }
7823 } else if( mod.typeId() == itype_waterproof_gunmod && has_flag( flag_WATERPROOF_GUN ) ) {
7824 return ret_val<bool>::make_failure( _( "is already waterproof" ) );
7825
7826 } else if( mod.typeId() == itype_tuned_mechanism && has_flag( flag_NEVER_JAMS ) ) {
7827 return ret_val<bool>::make_failure( _( "is already eminently reliable" ) );
7828
7829 } else if( mod.typeId() == itype_brass_catcher && has_flag( flag_RELOAD_EJECT ) ) {
7830 return ret_val<bool>::make_failure( _( "cannot have a brass catcher" ) );
7831
7832 } else if( ( !mod.type->mod->ammo_modifier.empty() || !mod.type->mod->magazine_adaptor.empty() )
7833 && ( ammo_remaining() > 0 || magazine_current() ) ) {
7834 return ret_val<bool>::make_failure( _( "must be unloaded before installing this mod" ) );
7835 }
7836
7837 for( const gunmod_location &slot : mod.type->gunmod->blacklist_mod ) {
7838 if( get_mod_locations().count( slot ) ) {
7839 return ret_val<bool>::make_failure( _( "cannot be installed on a weapon with \"%s\"" ),
7840 slot.name() );
7841 }
7842 }
7843
7845}
std::string name() const
Returns the translated name.
Definition: itype.cpp:15
gun_type_type gun_type() const
Get the type of a ranged weapon (e.g.
Definition: item.cpp:7203
static ret_val make_success(T val=default_success::value)
Definition: ret_val.h:42
static ret_val make_failure(T val=default_failure::value)
Definition: ret_val.h:46
static const std::string flag_RELOAD_EJECT("RELOAD_EJECT")
static const itype_id itype_brass_catcher("brass_catcher")
static const itype_id itype_hand_crossbow("hand_crossbow")
static const itype_id itype_waterproof_gunmod("waterproof_gunmod")
static const itype_id itype_tuned_mechanism("tuned_mechanism")
static const std::string flag_PUMP_ACTION("PUMP_ACTION")
static const std::string flag_NEVER_JAMS("NEVER_JAMS")
static const std::string flag_WATERPROOF_GUN("WATERPROOF_GUN")
static const std::string flag_PUMP_RAIL_COMPATIBLE("PUMP_RAIL_COMPATIBLE")
static const skill_id skill_archery("archery")

References _, ammo_remaining(), ammo_types(), count(), debugmsg, flag_NEVER_JAMS(), flag_PUMP_ACTION(), flag_PUMP_RAIL_COMPATIBLE(), flag_RELOAD_EJECT(), flag_WATERPROOF_GUN(), get_free_mod_locations(), get_mod_locations(), gun_skill(), gun_type(), gunmod_find(), has_flag(), is_gun(), is_gunmod(), itype_brass_catcher, itype_hand_crossbow, itype_tuned_mechanism, itype_waterproof_gunmod, magazine_current(), ret_val< T >::make_failure(), ret_val< T >::make_success(), gunmod_location::name(), skill_archery, translate_marker_context, and typeId().

Referenced by gunmod_inventory_preset::get_denial(), avatar_funcs::gunmod_add(), and activity_handlers::gunmod_add_finish().

◆ is_holster()

bool item::is_holster ( ) const

Definition at line 6585 of file item.cpp.

6586{
6587 return type->can_use( "holster" );
6588}

References itype::can_use(), and type.

Referenced by character_funcs::find_reloadables(), and get_total_capacity().

◆ is_irremovable()

bool item::is_irremovable ( ) const

Definition at line 6783 of file item.cpp.

6784{
6785 return has_flag( flag_IRREMOVABLE );
6786}
static const std::string flag_IRREMOVABLE("IRREMOVABLE")

References flag_IRREMOVABLE(), and has_flag().

Referenced by allow_crafting_component(), detach_gunmods_actor::can_use(), remove_ammo(), and detach_gunmods_actor::use().

◆ is_magazine()

◆ is_map()

bool item::is_map ( ) const

Definition at line 6722 of file item.cpp.

6723{
6724 return get_category().get_id() == itemcat_maps;
6725}
item_category_id get_id() const
static const item_category_id itemcat_maps("maps")

References get_category(), item_category::get_id(), and itemcat_maps.

Referenced by map::add_item(), and display_name().

◆ is_med_container()

bool item::is_med_container ( ) const

Definition at line 6623 of file item.cpp.

6624{
6625 return !contents.empty() && contents.front().is_medication();
6626}

References contents, item_contents::empty(), item_contents::front(), and is_medication().

Referenced by info().

◆ is_medication()

◆ is_melee() [1/2]

bool item::is_melee ( ) const

Is this item an effective melee weapon for any damage type?

See also
item::is_gun()
Note
an item can be both a gun and melee weapon concurrently

Definition at line 6675 of file item.cpp.

6676{
6677 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
6678 if( is_melee( static_cast<damage_type>( idx ) ) ) {
6679 return true;
6680 }
6681 }
6682 return false;
6683}

References DT_NULL, is_melee(), and NUM_DT.

Referenced by contextualize_skill(), is_melee(), melee_skill(), and on_wield().

◆ is_melee() [2/2]

bool item::is_melee ( damage_type  dt) const

Is this item an effective melee weapon for the given damage type?

Definition at line 6685 of file item.cpp.

6686{
6687 return damage_melee( dt ) > MELEE_STAT;
6688}
static constexpr int MELEE_STAT

References damage_melee(), and MELEE_STAT.

Referenced by iexamine::cvdmachine(), Character::i_add(), tutorial_game::post_action(), and npc::wield_better_weapon().

◆ is_money()

bool item::is_money ( ) const

Definition at line 6008 of file item.cpp.

6009{
6010 return ammo_types().count( ammotype( "money" ) );
6011}

References ammo_types().

Referenced by ammo_set(), display_name(), inventory_selector_preset::get_caption(), selection_column_preset::get_caption(), operator<(), and stacks_with().

◆ is_non_resealable_container()

bool item::is_non_resealable_container ( ) const

Whether removing this item's contents will permanently alter it.

Definition at line 6737 of file item.cpp.

6738{
6739 return type->container && !type->container->seals && type->container->unseals_into;
6740}

References itype::container, and type.

Referenced by deserialize(), advanced_inventory::move_content(), and on_contents_changed().

◆ is_null()

bool item::is_null ( ) const

Definition at line 735 of file item.cpp.

736{
737 // Actually, type should never by null at all.
738 return ( type == nullptr || type == nullitem() || typeId().is_null() );
739}

References is_null(), nullitem(), type, and typeId().

Referenced by acid_resist(), npc::address_needs(), ammo_set(), base_volume(), bash_resist(), Character::block_hit(), Character::block_ranged_hit(), bullet_resist(), Character::can_eat(), vehicle_part::can_reload(), repair_item_actor::can_repair_target(), Character::can_use(), debug_menu::character_edit_menu(), color(), colorized_feature_description_at(), veh_interact::complete_vehicle(), conductive(), Character::consume_item(), cut_resist(), damage_melee(), display_name(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), drop_or_embed_projectile(), enumerate_objects_around_point(), Character::extended_description(), final_info(), find_auto_consume(), fire_resist(), inventory::form_from_map(), iexamine::gaspump(), liquid_handler::get_liquid_target(), SkillLevelMap::get_skill_level(), aim_activity_actor::get_weapon(), Character::handle_melee_wear(), npc::has_healing_item(), npc::heal_player(), npc::heal_self(), Character::i_add_or_drop(), info(), npc_trading::init_buying(), Character::is_armed(), is_null(), is_old_owner(), is_owned_by(), is_salvageable(), is_unarmed_weapon(), Character::item_encumb(), Character::item_reload_cost(), npc::load(), made_of(), Character::meets_requirements(), Character::melee_attack(), melee_train(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), monexamine::pet_menu(), photo_def_for_camera_point(), rcdrive(), player::reduce_charges(), reinforceable(), bandolier_actor::reload(), reload(), Character::roll_bash_damage(), Character::roll_cut_damage(), Character::roll_stab_damage(), projectile::set_drop(), set_snippet(), npc::shop_restock(), map::spawn_items(), starting_inv(), Character::store(), npc::store(), holster_actor::store(), Character::suffer_from_schizophrenia(), Character::throw_range(), tname(), salvage_actor::try_to_cut_up(), Character::unarmed_attack(), Character::unwield(), avatar_funcs::use_item(), npc::use_painkiller(), salvage_actor::valid_to_cut_up(), volume(), martialart::weapon_valid(), Character::wear_possessed(), weight(), npc::wield(), avatar::wield(), and npc::wield_better_weapon().

◆ is_old_owner()

bool item::is_old_owner ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1252 of file item.cpp.

1253{
1254 if( get_old_owner().is_null() ) {
1255 return available_to_take;
1256 }
1257 if( !c.get_faction() ) {
1258 debugmsg( "Character %s has no faction.", c.disp_name() );
1259 return false;
1260 }
1261 return c.get_faction()->id == get_old_owner();
1262}
faction_id get_old_owner() const
Definition: item.cpp:1288

References c, debugmsg, get_old_owner(), and is_null().

◆ is_owned_by()

bool item::is_owned_by ( const Character c,
bool  available_to_take = false 
) const

Definition at line 1237 of file item.cpp.

1238{
1239 // owner.is_null() implies faction_id( "no_faction" ) which shouldn't happen, or no owner at all.
1240 // either way, certain situations this means the thing is available to take.
1241 // in other scenarios we actually really want to check for id == id, even for no_faction
1242 if( get_owner().is_null() ) {
1243 return available_to_take;
1244 }
1245 if( !c.get_faction() ) {
1246 debugmsg( "Character %s has no faction", c.disp_name() );
1247 return false;
1248 }
1249 return c.get_faction()->id == get_owner();
1250}

References c, debugmsg, get_owner(), and is_null().

Referenced by activity_on_turn_move_loot(), move_items_activity_actor::do_turn(), find_auto_consume(), handle_pickup_ownership(), npc_trading::init_buying(), pick_one_up(), pickup::pick_up(), query_consume_ownership(), and npc::wants_to_sell().

◆ is_pet_armor()

bool item::is_pet_armor ( bool  on_pet = false) const

Definition at line 6706 of file item.cpp.

6707{
6708 bool is_worn = on_pet && !get_var( "pet_armor", "" ).empty();
6709 return has_flag( flag_IS_PET_ARMOR ) && ( is_worn || !on_pet );
6710}
static const std::string flag_IS_PET_ARMOR("IS_PET_ARMOR")

References flag_IS_PET_ARMOR(), get_var(), and has_flag().

Referenced by animal_armor_info(), armor_protection_info(), get_base_env_resist(), get_base_env_resist_w_filter(), get_env_resist(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_storage(), and get_thickness().

◆ is_power_armor()

bool item::is_power_armor ( ) const

Whether this is a power armor item.

Not necessarily the main armor, it could be a helmet or similar.

Definition at line 5794 of file item.cpp.

5795{
5798}
static const std::string flag_POWERARMOR_MOD("POWERARMOR_MOD")

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by armor_fit_info(), Character::can_wear(), Character::consume_charges(), final_info(), Character::has_enough_charges(), process_tool(), units_remaining(), and set_transform_iuse::use().

◆ is_relic()

bool item::is_relic ( ) const

Definition at line 6981 of file item.cpp.

6982{
6983 return !!relic_data;
6984}

References relic_data.

Referenced by get_enchantments(), mutations_from_wearing(), process_relic(), and stacks_with().

◆ is_reloadable()

bool item::is_reloadable ( ) const

Is it ever possible to reload this item? Only the base item is considered with any mods ignored.

See also
player::can_reload()

Definition at line 9851 of file item.cpp.

9852{
9854 return false; // turrets ignore NO_RELOAD flag
9855
9856 } else if( is_bandolier() ) {
9857 return true;
9858
9859 } else if( is_container() ) {
9860 return true;
9861
9862 } else if( !is_gun() && !is_tool() && !is_magazine() ) {
9863 return false;
9864
9865 } else if( ammo_types().empty() ) {
9866 return false;
9867 }
9868
9869 return true;
9870}
static const std::string flag_VEHICLE("VEHICLE")

References ammo_types(), flag_NO_RELOAD(), flag_VEHICLE(), has_flag(), is_bandolier(), is_container(), is_gun(), is_magazine(), and is_tool().

Referenced by can_reload_item_or_mods(), is_reloadable_helper(), and examine_item_menu::rate_action_reload().

◆ is_reloadable_helper()

bool item::is_reloadable_helper ( const itype_id ammo,
bool  now 
) const
private

Helper for checking reloadability.

Definition at line 6884 of file item.cpp.

6885{
6886 // empty ammo is passed for listing possible ammo apparently, so it needs to return true.
6887 if( !is_reloadable() ) {
6888 return false;
6889 } else if( is_watertight_container() ) {
6890 if( ammo.is_empty() ) {
6891 return now ? !is_container_full() : true;
6892 } else if( ammo->phase != LIQUID ) {
6893 return false;
6894 } else {
6895 return now ? ( is_container_empty() || contents.front().typeId() == ammo ) : true;
6896 }
6897 } else if( magazine_integral() ) {
6898 if( !ammo.is_empty() ) {
6899 if( now && ammo_data() ) {
6900 if( ammo_current() != ammo ) {
6901 return false;
6902 }
6903 } else {
6904 const itype *at = &*ammo;
6905 if( ( !at->ammo || !ammo_types().count( at->ammo->type ) ) &&
6906 !magazine_compatible().count( ammo ) ) {
6907 return false;
6908 }
6909 }
6910 }
6911 return now ? ( ammo_remaining() < ammo_capacity() ) : true;
6912 } else {
6913 return ammo.is_empty() ? true : magazine_compatible().count( ammo );
6914 }
6915}
bool is_reloadable() const
Is it ever possible to reload this item? Only the base item is considered with any mods ignored.
Definition: item.cpp:9851
bool is_container_full(bool allow_bucket=false) const
Whether this item has no more free capacity for its current content.
Definition: item.cpp:6850

References itype::ammo, ammo_capacity(), ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), contents, count(), item_contents::front(), is_container_empty(), is_container_full(), string_id< T >::is_empty(), is_reloadable(), is_watertight_container(), LIQUID, magazine_compatible(), magazine_integral(), itype::phase, and typeId().

Referenced by can_reload_with(), and is_reloadable_with().

◆ is_reloadable_with()

bool item::is_reloadable_with ( const itype_id ammo) const

Returns true if this item can be reloaded with specified ammo type at this moment.

Definition at line 6879 of file item.cpp.

6880{
6881 return is_reloadable_helper( ammo, true );
6882}

References is_reloadable_helper().

Referenced by Character::can_reload(), vehicle_part::can_reload(), fill_with(), get_remaining_capacity_for_liquid(), and reload().

◆ is_salvageable()

bool item::is_salvageable ( ) const

Definition at line 6917 of file item.cpp.

6918{
6919 if( is_null() ) {
6920 return false;
6921 }
6922 const std::vector<material_id> &mats = made_of();
6923 if( std::none_of( mats.begin(), mats.end(), []( const material_id & m ) {
6924 return m->salvaged_into().has_value();
6925 } ) ) {
6926 return false;
6927 }
6928 return !has_flag( flag_NO_SALVAGE );
6929}
static const std::string flag_NO_SALVAGE("NO_SALVAGE")

References flag_NO_SALVAGE(), has_flag(), is_null(), and made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ is_seed()

bool item::is_seed ( ) const

Whether this is actually a seed, the seed functions won't be of much use for non-seeds.

Definition at line 9795 of file item.cpp.

9796{
9797 return !!type->seed;
9798}

References itype::seed, and type.

Referenced by can_do_activity_there(), iexamine::dirtmound(), farm_valid_seed(), talk_function::field_plant(), plot_options::get_zone_name_suggestion(), plot_options::query_seed(), vehicle::reload_seeds(), and map::rotten_item_spawn().

◆ is_sided()

bool item::is_sided ( ) const

Returns true if item is armor and can be worn on different sides of the body.

Definition at line 805 of file item.cpp.

806{
807 const islot_armor *t = find_armor_data();
808 return t ? t->sided : false;
809}

References find_armor_data(), and islot_armor::sided.

Referenced by armor_fit_info(), armor_info(), Character::can_wear(), on_takeoff(), on_wear(), examine_item_menu::rate_action_change_side(), and set_side().

◆ is_silent()

bool item::is_silent ( ) const

Whether this is a (nearly) silent gun (a tiny bit of sound is allowed).

Non-guns are always silent.

Definition at line 6550 of file item.cpp.

6551{
6552 return gun_noise().volume < 5;
6553}
sound_data gun_noise(bool burst=false) const
Returns the sound of the gun being fired.
Definition: ranged.cpp:1815
int volume
Volume of the sound.
Definition: item.h:1851

References gun_noise(), and item::sound_data::volume.

Referenced by npc::check_or_use_weapon_cbm(), and npc::method_of_attack().

◆ is_soft()

bool item::is_soft ( ) const

Is this item flexible enough to be worn on body parts like antlers?

Definition at line 9843 of file item.cpp.

9844{
9845 const std::vector<material_id> mats = made_of();
9846 return std::any_of( mats.begin(), mats.end(), []( const material_id & mid ) {
9847 return mid.obj().soft();
9848 } );
9849}

References made_of().

Referenced by mutation_branch::conflicts_with_item(), and game_menus::inv::multiwash().

◆ is_tainted()

bool item::is_tainted ( ) const

Is item derived from a zombie?

Definition at line 9838 of file item.cpp.

9839{
9840 return corpse && corpse->has_flag( MF_POISON );
9841}
@ MF_POISON
Definition: mtype.h:80

References corpse, mtype::has_flag(), and MF_POISON.

Referenced by food_info().

◆ is_tool()

◆ is_toolmod()

bool item::is_toolmod ( ) const

Definition at line 6773 of file item.cpp.

6774{
6775 return !is_gunmod() && type->mod;
6776}

References is_gunmod(), itype::mod, and type.

Referenced by allow_crafting_component(), item_action_generator::map_actions_to_items(), iuse::multicooker(), and iuse::toolmod_attach().

◆ is_transformable()

bool item::is_transformable ( ) const

Definition at line 6971 of file item.cpp.

6972{
6973 return type->use_methods.find( "transform" ) != type->use_methods.end();
6974}

References type, and itype::use_methods.

Referenced by map::add_item().

◆ is_two_handed()

bool item::is_two_handed ( const Character guy) const

Whether the character needs both hands to wield this item.

Strength determines which weapons can be wielded with one hand

Definition at line 6412 of file item.cpp.

6413{
6414 if( has_flag( flag_ALWAYS_TWOHAND ) ) {
6415 return true;
6416 }
6417 ///\EFFECT_STR determines which weapons can be wielded with one hand
6418 return ( ( weight() / 113_gram ) > guy.str_cur * 4 );
6419}
int str_cur
Definition: character.h:264
static const std::string flag_ALWAYS_TWOHAND("ALWAYS_TWOHAND")

References flag_ALWAYS_TWOHAND(), has_flag(), Character::str_cur, and weight().

Referenced by Character::can_wear(), Character::can_wield(), ranged::gunmode_checks_common(), hardcoded_mutation_attack(), Character::item_handling_cost(), and Character::melee_special_effects().

◆ is_unarmed_weapon()

bool item::is_unarmed_weapon ( ) const

Definition at line 741 of file item.cpp.

742{
743 return has_flag( flag_UNARMED_WEAPON ) || is_null();
744}
static const std::string flag_UNARMED_WEAPON("UNARMED_WEAPON")

References flag_UNARMED_WEAPON(), has_flag(), and is_null().

Referenced by Character::crit_chance(), melee_train(), Character::roll_bash_damage(), Character::roll_cut_damage(), and Character::roll_stab_damage().

◆ is_upgrade()

bool item::is_upgrade ( ) const

Whether the CBM is an upgrade to another bionic module.

Definition at line 10057 of file item.cpp.

10058{
10059 if( !type->bionic ) {
10060 return false;
10061 }
10062 return type->bionic->is_upgrade;
10063}

References itype::bionic, and type.

Referenced by bionic_install_preset::get_denial(), and bionic_install_surgeon_preset::get_denial().

◆ is_watertight_container()

bool item::is_watertight_container ( ) const

◆ is_wheel()

bool item::is_wheel ( ) const

Definition at line 6763 of file item.cpp.

6764{
6765 return !!type->wheel;
6766}
cata::value_ptr< islot_wheel > wheel
Definition: itype.h:857

References type, and itype::wheel.

Referenced by can_do_activity_there(), tname(), wheel_area(), vehicle_part::wheel_diameter(), and vehicle_part::wheel_width().

◆ is_worn_only_with()

bool item::is_worn_only_with ( const item it) const

Returns true whether this item can be worn only when.

Parameters
itis worn.

Definition at line 838 of file item.cpp.

839{
842}

References flag_POWERARMOR_EXO(), flag_POWERARMOR_EXTERNAL(), flag_POWERARMOR_MOD(), and has_flag().

Referenced by Character::get_dependent_worn_items(), and pickup::reorder_for_dropping().

◆ item_has_uses_recursive()

bool item::item_has_uses_recursive ( ) const

Definition at line 80 of file item_action.cpp.

81{
82 if( !type->use_methods.empty() ) {
83 return true;
84 }
85
87}
bool item_has_uses_recursive() const
Definition: item_action.cpp:89

References contents, item_contents::item_has_uses_recursive(), type, and itype::use_methods.

◆ label()

std::string item::label ( unsigned int  quantity = 0) const

Returns label from "item_label" itemvar and quantity.

Definition at line 9973 of file item.cpp.

9974{
9975 if( has_label() ) {
9976 return get_var( "item_label" );
9977 }
9978
9979 return type_name( quantity );
9980}
std::string type_name(unsigned int quantity=1) const
Name of the item type (not the item), with proper plural.
Definition: item.cpp:9872
bool has_label() const
Returns true if item has "item_label" itemvar.
Definition: item.cpp:9968

References get_var(), has_label(), and type_name().

Referenced by tname().

◆ legacy_fast_forward_time()

void item::legacy_fast_forward_time ( )

Definition at line 10036 of file item.cpp.

10037{
10038 const time_duration tmp_bday = ( bday - calendar::turn_zero ) * 6;
10039 bday = calendar::turn_zero + tmp_bday;
10040
10041 rot *= 6;
10042
10043 const time_duration tmp_rot = ( last_rot_check - calendar::turn_zero ) * 6;
10045}

References bday, last_rot_check, and calendar::turn_zero.

Referenced by deserialize(), and submap::load().

◆ lift_strength()

int item::lift_strength ( ) const

Required strength to be able to successfully lift the item unaided by equipment.

Definition at line 5183 of file item.cpp.

5184{
5185 const int mass = units::to_gram( weight() );
5186 return std::max( mass / 10000, 1 );
5187}
constexpr value_type to_gram(const quantity< value_type, mass_in_milligram_tag > &v)
Definition: units_mass.h:68
quantity< std::int64_t, mass_in_milligram_tag > mass
Definition: units_mass.h:23

References units::to_gram(), and weight().

Referenced by can_do_activity_there(), veh_interact::can_remove_part(), and veh_interact::update_part_requirements().

◆ made_of() [1/3]

const std::vector< material_id > & item::made_of ( ) const

The ids of all the materials this is made of.

This may return an empty vector. The returned vector does not contain the null id.

Definition at line 6421 of file item.cpp.

6422{
6423 if( is_corpse() ) {
6424 return corpse->mat;
6425 }
6426 return type->materials;
6427}
std::vector< material_id > materials
Definition: itype.h:922
std::vector< material_id > mat
Definition: mtype.h:254

References corpse, is_corpse(), mtype::mat, itype::materials, and type.

Referenced by activity_on_turn_move_loot(), map::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), iuse::blech(), iuse::blech_because_unclean(), vehicle_part::can_reload(), can_unload_liquid(), saw_stock_actor::can_use_on(), Character::can_wear(), Character::can_wield(), MonsterGenerator::check_monster_definitions(), color_in_inventory(), crafting::complete_disassemble(), compute_default_effective_vitamins(), contents_made_of(), map::create_burnproducts(), auto_pickup::rule_list::create_rule(), salvage_actor::cut_up(), iexamine::cvdmachine(), move_items_activity_actor::do_turn(), Character::drop_invalid_inventory(), drop_or_handle(), final_info(), character_funcs::find_ammo_helper(), iexamine::fvat_empty(), iexamine::fvat_full(), Character::get_acquirable_energy(), get_base_material(), pickup_inventory_preset::get_denial(), comestible_inventory_preset::get_denial(), liquid_handler::get_liquid_target(), get_random_material(), repair_item_actor::handle_components(), liquid_handler::handle_liquid(), Character::i_add_or_drop(), in_container(), is_salvageable(), is_soft(), inscribe_actor::item_inscription(), iexamine::keg(), made_of(), made_of_any(), made_of_types(), Character::melee_special_effects(), Item_modifier::modify(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_pickup_from_stack(), on_drop(), only_made_of(), liquid_handler::perform_liquid_transfer(), pick_one_up(), price(), monster::process_turn(), mattack::pull_metal_weapon(), item_reload_option::qty(), advanced_inventory::query_charges(), reload(), simulate_burn(), smash(), map::spawn_an_item(), starting_inv(), ranged::throw_item(), tname(), try_fuel_fire(), avatar_funcs::unload_item(), npc::value(), volume(), and Character::warmth().

◆ made_of() [2/3]

bool item::made_of ( const material_id mat_ident) const

Check we are made of this material (e.g.

matches at least one in our set.)

Definition at line 6467 of file item.cpp.

6468{
6469 const std::vector<material_id> &materials = made_of();
6470 return std::find( materials.begin(), materials.end(), mat_ident ) != materials.end();
6471}

References detail::find(), and made_of().

◆ made_of() [3/3]

bool item::made_of ( phase_id  phase) const

Are we solid, liquid, gas, plasma?

Definition at line 6478 of file item.cpp.

6479{
6480 if( is_null() ) {
6481 return false;
6482 }
6483 return type->phase == phase;
6484}

References is_null(), itype::phase, and type.

◆ made_of_any()

bool item::made_of_any ( const std::set< material_id > &  mat_idents) const

Check we are made of at least one of a set (e.g.

true if at least one item of the passed in set matches any material).

Parameters
mat_identsSet of material ids.

Definition at line 6443 of file item.cpp.

6444{
6445 const std::vector<material_id> &mats = made_of();
6446 if( mats.empty() ) {
6447 return false;
6448 }
6449
6450 return std::any_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6451 return mat_idents.count( e );
6452 } );
6453}

References made_of().

Referenced by Character::can_eat(), goes_bad(), repair_inventory_preset::is_shown(), inscribe_actor::item_inscription(), ranged::throw_item(), and Character::throw_range().

◆ made_of_types()

std::vector< const material_type * > item::made_of_types ( ) const

Same as made_of(), but returns the material_type directly.

Definition at line 6434 of file item.cpp.

6435{
6436 std::vector<const material_type *> material_types_composed_of;
6437 for( const material_id &mat_id : made_of() ) {
6438 material_types_composed_of.push_back( &mat_id.obj() );
6439 }
6440 return material_types_composed_of;
6441}

References made_of().

Referenced by acid_resist(), bash_resist(), basic_info(), bullet_resist(), chip_resistance(), conductive(), cut_resist(), fire_resist(), flammable(), reinforceable(), and wind_resist().

◆ magazine_compatible()

std::set< itype_id > item::magazine_compatible ( bool  conversion = true) const

Get compatible magazines (if any) for this item.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine compatibility which is always empty if item has integral magazine
See also
item::magazine_integral

Definition at line 7709 of file item.cpp.

7710{
7711 std::set<itype_id> mags = {};
7712 // mods that define magazine_adaptor may override the items usual magazines
7713 const std::vector<const item *> &mods = is_gun() ? gunmods() : toolmods();
7714 for( const item *m : mods ) {
7715 if( !m->type->mod->magazine_adaptor.empty() ) {
7716 for( const ammotype &atype : ammo_types( conversion ) ) {
7717 if( m->type->mod->magazine_adaptor.count( atype ) ) {
7718 std::set<itype_id> magazines_for_atype = m->type->mod->magazine_adaptor.find( atype )->second;
7719 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7720 }
7721 }
7722 return mags;
7723 }
7724 }
7725
7726 for( const ammotype &atype : ammo_types( conversion ) ) {
7727 if( type->magazines.count( atype ) ) {
7728 std::set<itype_id> magazines_for_atype = type->magazines.find( atype )->second;
7729 mags.insert( magazines_for_atype.begin(), magazines_for_atype.end() );
7730 }
7731 }
7732 return mags;
7733}

References ammo_types(), gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by mdeath::broken(), color_in_inventory(), character_funcs::find_reloadables(), gun_info(), avatar_funcs::gunmod_add(), is_reloadable_helper(), and tool_info().

◆ magazine_current() [1/2]

item * item::magazine_current ( )

Currently loaded magazine (if any)

Returns
current magazine or nullptr if either no magazine loaded or item has integral magazine
See also
item::magazine_integral

Definition at line 7735 of file item.cpp.

7736{
7737 return contents.get_item_with(
7738 []( const item & it ) {
7739 return it.is_magazine();
7740 } );
7741}
item * get_item_with(const std::function< bool(const item &)> &filter)

References contents, item_contents::get_item_with(), and is_magazine().

Referenced by ammo_capacity(), ammo_consume(), ammo_data(), ammo_remaining(), ammo_set(), ammo_unset(), item_funcs::can_be_unloaded(), turret_data::can_unload(), common_ammo_default(), cycle_action(), iuse::foodperson(), iuse::hand_crank(), is_gunmod_compatible(), character_funcs::list_ammo(), magazine_current(), Item_modifier::modify(), reload(), character_funcs::select_ammo(), tool_info(), iuse::toolmod_attach(), avatar_funcs::unload_item(), volume(), and weight().

◆ magazine_current() [2/2]

const item * item::magazine_current ( ) const

Definition at line 7743 of file item.cpp.

7744{
7745 return const_cast<item *>( this )->magazine_current();
7746}

References magazine_current().

◆ magazine_default()

itype_id item::magazine_default ( bool  conversion = true) const

Get the default magazine type (if any) for the current effective ammo type.

Parameters
conversionwhether to include the effect of any flags or mods which convert item's ammo type
Returns
magazine type or "null" if item has integral magazine or no magazines for current ammo type

Definition at line 7688 of file item.cpp.

7689{
7690 if( !ammo_types( conversion ).empty() ) {
7691 if( conversion ) {
7692 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7693 if( !m->type->mod->magazine_adaptor.empty() ) {
7694 auto mags = m->type->mod->magazine_adaptor.find( ammotype( *ammo_types( conversion ).begin() ) );
7695 if( mags != m->type->mod->magazine_adaptor.end() ) {
7696 return *( mags->second.begin() );
7697 }
7698 }
7699 }
7700 }
7701 auto mag = type->magazine_default.find( ammotype( *ammo_types( conversion ).begin() ) );
7702 if( mag != type->magazine_default.end() ) {
7703 return mag->second;
7704 }
7705 }
7706 return itype_id::NULL_ID();
7707}
std::map< ammotype, itype_id > magazine_default
Default magazine for each ammo type that can be used to reload this item.
Definition: itype.h:1023

References ammo_types(), gunmods(), is_gun(), itype::magazine_default, itype::mod, string_id< itype >::NULL_ID(), toolmods(), and type.

Referenced by ammo_capacity(), ammo_set(), defense_game::caravan(), game::dump_stats(), and Item_modifier::modify().

◆ magazine_info()

void item::magazine_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1884 of file item.cpp.

1886{
1887 if( !is_magazine() || has_flag( flag_NO_RELOAD ) ) {
1888 return;
1889 }
1890
1891 if( parts->test( iteminfo_parts::MAGAZINE_CAPACITY ) ) {
1892 for( const ammotype &at : ammo_types() ) {
1893 const std::string fmt = string_format( vgettext( "<num> round of %s",
1894 "<num> rounds of %s", ammo_capacity() ),
1895 at->name() );
1896 info.emplace_back( "MAGAZINE", _( "Capacity: " ), fmt, iteminfo::no_flags,
1897 ammo_capacity() );
1898 }
1899 }
1900 if( parts->test( iteminfo_parts::MAGAZINE_RELOAD ) ) {
1901 info.emplace_back( "MAGAZINE", _( "Reload time: " ), _( "<num> moves per round" ),
1902 iteminfo::lower_is_better, type->magazine->reload_time );
1903 }
1905}

References _, ammo_capacity(), ammo_types(), flag_NO_RELOAD(), has_flag(), info(), insert_separation_line(), is_magazine(), iteminfo::lower_is_better, itype::magazine, MAGAZINE_CAPACITY, MAGAZINE_RELOAD, iteminfo::no_flags, string_format(), iteminfo_query::test(), type, and vgettext().

Referenced by info().

◆ magazine_integral()

bool item::magazine_integral ( ) const

Does item have an integral magazine (as opposed to allowing detachable magazines)

Definition at line 7673 of file item.cpp.

7674{
7675 if( is_gun() && type->gun->clip > 0 ) {
7676 return true;
7677 }
7678 for( const item *m : is_gun() ? gunmods() : toolmods() ) {
7679 if( !m->type->mod->magazine_adaptor.empty() ) {
7680 return false;
7681 }
7682 }
7683
7684 // We have an integral magazine if we're a gun with an ammo capacity (clip) or we have no magazines.
7685 return ( is_gun() && type->gun->clip > 0 ) || type->magazines.empty();
7686}

References itype::gun, gunmods(), is_gun(), itype::magazines, toolmods(), and type.

Referenced by character_funcs::ammo_count_for(), ammo_set(), ammo_unset(), turret_data::can_reload(), defense_game::caravan(), color_in_inventory(), game::dump_stats(), character_funcs::fmt_wielded_weapon(), gun_info(), avatar_funcs::gunmod_add(), ideal_ranged_dps(), is_reloadable_helper(), item(), Item_modifier::modify(), price(), reload(), character_funcs::select_ammo(), tool_info(), wants_to_reload_with(), and weight().

◆ make_component_hash()

uint64_t item::make_component_hash ( ) const

Creates a hash from the itype_ids of this item's components.

Definition at line 8926 of file item.cpp.

8927{
8928 // First we need to sort the IDs so that identical ingredients give identical hashes.
8929 std::multiset<std::string> id_set;
8930 for( const item &it : components ) {
8931 id_set.insert( it.typeId().str() );
8932 }
8933
8934 std::string concatenated_ids;
8935 for( std::string id : id_set ) {
8936 concatenated_ids += id;
8937 }
8938
8939 std::hash<std::string> hasher;
8940 return hasher( concatenated_ids );
8941}

References components, base_camps::id, and string_id< T >::str().

Referenced by consumption_event::consumption_event(), and Character::fun_for().

◆ make_corpse()

item item::make_corpse ( const mtype_id mt = string_id<mtype>::NULL_ID(),
time_point  turn = calendar::turn,
const std::string &  name = "",
int  upgrade_time = -1 
)
static

Make a corpse of the given monster type.

The monster type id must be valid (see MonsterGenerator::get_all_mtypes).

The turn parameter sets the birthday of the corpse, in other words: the turn when the monster died. Because corpses are removed from the map when they reach a certain age, one has to be careful when placing corpses with a birthday of 0. They might be removed immediately when the map is loaded without been seen by the player.

The name parameter can be used to give the corpse item a name. This is used instead of the monster type name ("corpse of X" instead of "corpse of bear").

With the default parameters it makes a human corpse, created at the current turn.

Definition at line 510 of file item.cpp.

512{
513 if( !mt.is_valid() ) {
514 debugmsg( "tried to make a corpse with an invalid mtype id" );
515 }
516
517 std::string corpse_type = mt == mtype_id::NULL_ID() ? "corpse_generic_human" : "corpse";
518
519 item result( corpse_type, turn );
520 result.corpse = &mt.obj();
521
522 if( result.corpse->has_flag( MF_REVIVES ) ) {
523 if( one_in( 20 ) ) {
524 result.set_flag( "REVIVE_SPECIAL" );
525 }
526 result.set_var( "upgrade_time", std::to_string( upgrade_time ) );
527 }
528
529 // This is unconditional because the const itemructor above sets result.name to
530 // "human corpse".
531 result.corpse_name = name;
532
533 return result;
534}
std::string to_string(const time_duration &d)
Returns a string showing a duration.
Definition: calendar.cpp:327
bool one_in(int chance)
Definition: rng.cpp:65

References debugmsg, string_id< T >::is_valid(), MF_REVIVES, om_direction::name(), string_id< mtype >::NULL_ID(), string_id< T >::obj(), one_in(), to_string(), and calendar::turn.

Referenced by map::add_corpse(), game::catch_a_monster(), Single_item_creator::create_single(), map::draw_mine(), iuse::fish_trap(), basecamp::hunting_results(), make_mon_corpse(), MapExtras::mx_grave(), MapExtras::mx_mayhem(), MapExtras::mx_minefield(), Character::place_corpse(), rod_fish(), and mdeath::splatter().

◆ mark_as_used_by_player()

void item::mark_as_used_by_player ( const player p)

Marks the item as being used by this specific player, it remains unmarked for other players.

The player is identified by its id.

Definition at line 8874 of file item.cpp.

8875{
8876 std::string &used_by_ids = item_vars[ USED_BY_IDS ];
8877 if( used_by_ids.empty() ) {
8878 // *always* start with a ';'
8879 used_by_ids = ";";
8880 }
8881 // and always end with a ';'
8882 used_by_ids += string_format( "%d;", p.getID().get_value() );
8883}

References character_id::get_value(), Character::getID(), item_vars, string_format(), and USED_BY_IDS().

Referenced by reveal_map_actor::use().

◆ mark_chapter_as_read()

void item::mark_chapter_as_read ( const Character ch)

Mark one chapter of the book as read by the given player.

May do nothing if the book has no unread chapters. This is a per-character setting, see get_remaining_chapters.

Definition at line 7111 of file item.cpp.

7112{
7113 const std::string var = string_format( "remaining-chapters-%d", ch.getID().get_value() );
7114 if( type->book && type->book->chapters == 0 ) {
7115 // books without chapters will always have remaining chapters == 0, so we don't need to store them
7116 erase_var( var );
7117 return;
7118 }
7119 const int remain = std::max( 0, get_remaining_chapters( ch ) - 1 );
7120 set_var( var, remain );
7121}
void erase_var(const std::string &name)
Erase the value of the given variable.
Definition: item.cpp:1083

References itype::book, erase_var(), get_remaining_chapters(), character_id::get_value(), Character::getID(), set_var(), string_format(), and type.

Referenced by avatar::do_read(), and npc::finish_read().

◆ max_damage()

◆ med_info()

void item::med_info ( const item med_item,
std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 1644 of file item.cpp.

1646{
1647 const cata::value_ptr<islot_comestible> &med_com = med_item->get_comestible();
1648 if( med_com->quench != 0 && parts->test( iteminfo_parts::MED_QUENCH ) ) {
1649 info.push_back( iteminfo( "MED", _( "Quench: " ), med_com->quench ) );
1650 }
1651
1652 if( med_item->get_comestible_fun() != 0 && parts->test( iteminfo_parts::MED_JOY ) ) {
1653 info.push_back( iteminfo( "MED", _( "Enjoyability: " ),
1654 get_avatar().fun_for( *med_item ).first ) );
1655 }
1656
1657 if( med_com->stim != 0 && parts->test( iteminfo_parts::MED_STIMULATION ) ) {
1658 std::string name = string_format( "%s <stat>%s</stat>", _( "Stimulation:" ),
1659 med_com->stim > 0 ? _( "Upper" ) : _( "Downer" ) );
1660 info.push_back( iteminfo( "MED", name ) );
1661 }
1662
1663 if( parts->test( iteminfo_parts::MED_PORTIONS ) ) {
1664 info.push_back( iteminfo( "MED", _( "Portions: " ),
1665 std::abs( static_cast<int>( med_item->charges ) * batch ) ) );
1666 }
1667
1668 if( med_com->addict && parts->test( iteminfo_parts::DESCRIPTION_MED_ADDICTING ) ) {
1669 info.emplace_back( "DESCRIPTION", _( "* Consuming this item is <bad>addicting</bad>." ) );
1670 }
1671}
int get_comestible_fun() const
Definition: item.cpp:5490

References _, charges, DESCRIPTION_MED_ADDICTING, get_avatar(), get_comestible(), get_comestible_fun(), info(), MED_JOY, MED_PORTIONS, MED_QUENCH, MED_STIMULATION, om_direction::name(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ melee_skill()

skill_id item::melee_skill ( ) const

The most relevant skill used with this melee weapon.

Can be "null" if this is not a weapon. Note this function returns null if the item is a gun for which you can use gun_skill() instead.

Definition at line 7216 of file item.cpp.

7217{
7218 if( !is_melee() ) {
7219 return skill_id::NULL_ID();
7220 }
7221
7222 if( has_flag( flag_UNARMED_WEAPON ) ) {
7223 return skill_unarmed;
7224 }
7225
7226 int hi = 0;
7228
7229 for( int idx = DT_NULL + 1; idx != NUM_DT; ++idx ) {
7230 const int val = damage_melee( static_cast<damage_type>( idx ) );
7231 const skill_id &sk = skill_by_dt( static_cast<damage_type>( idx ) );
7232 if( val > hi && sk ) {
7233 hi = val;
7234 res = sk;
7235 }
7236 }
7237
7238 return res;
7239}
const skill_id & skill_by_dt(damage_type dt)
Definition: damage.cpp:273
static const skill_id skill_unarmed("unarmed")

References damage_melee(), DT_NULL, flag_UNARMED_WEAPON(), has_flag(), is_melee(), string_id< Skill >::NULL_ID(), NUM_DT, skill_by_dt(), and skill_unarmed.

Referenced by contextualize_skill(), Character::crit_chance(), Character::get_hit_weapon(), Character::item_store_cost(), on_wield(), and character_funcs::try_wield_contents().

◆ merge_charges()

bool item::merge_charges ( const item rhs)

Merge charges of the other item into this item.

Returns
true if the items have been merged, otherwise false. Merging is only done for items counted by charges (count_by_charges) and items that stack together (stacks_with).

Definition at line 979 of file item.cpp.

980{
981 if( !count_by_charges() || !stacks_with( rhs ) ) {
982 return false;
983 }
984 // Prevent overflow when either item has "near infinite" charges.
985 if( charges >= INFINITE_CHARGES / 2 || rhs.charges >= INFINITE_CHARGES / 2 ) {
987 return true;
988 }
989 // We'll just hope that the item counter represents the same thing for both items
990 if( item_counter > 0 || rhs.item_counter > 0 ) {
991 item_counter = ( static_cast<double>( item_counter ) * charges + static_cast<double>
992 ( rhs.item_counter ) * rhs.charges ) / ( charges + rhs.charges );
993 }
994 charges += rhs.charges;
995 return true;
996}

References charges, count_by_charges(), INFINITE_CHARGES, item_counter, and stacks_with().

Referenced by vehicle::add_item().

◆ min_damage()

int item::min_damage ( ) const

Minimum amount of damage to an item (state of maximum repair)

Definition at line 6219 of file item.cpp.

6220{
6221 return type->damage_min();
6222}
int damage_min() const
Definition: itype.cpp:46

References itype::damage_min(), and type.

Referenced by repair_item_actor::can_repair_target(), damage_color(), repair_item_actor::default_action(), iuse::gun_repair(), io(), mod_damage(), and set_damage().

◆ minimum_freshness_duration()

time_duration item::minimum_freshness_duration ( temperature_flag  temperature) const

Time that this item is guaranteed to stay fresh.

Parameters
temperatureTemperature flag used to cap the duration.
Returns
Remaining guaranteed freshness duration, assuming current storage conditions.

Definition at line 5708 of file item.cpp.

5709{
5711 unsigned long long rot_per_hour = get_hourly_rotpoints_at_temp( temperature_f );
5712
5713 if( rot_per_hour <= 0 || !type->comestible ) {
5715 }
5716
5717 time_duration remaining_rot = type->comestible->spoils - rot;
5718 // Has to be in int64 or it will overflow for long lasting food
5719 unsigned long long duration = to_turns<unsigned long long>( remaining_rot )
5720 * to_turns<unsigned long long>( 1_hours )
5721 / rot_per_hour;
5722 if( duration > to_turns<unsigned long long>( calendar::INDEFINITELY_LONG_DURATION ) ) {
5724 }
5725
5726 return time_duration::from_turns( static_cast<int>( duration ) );
5727}
static int temperature_flag_to_highest_temperature(temperature_flag temperature)
Definition: item.cpp:5690
const time_duration INDEFINITELY_LONG_DURATION
The expected duration of the cataclysm.

References itype::comestible, time_duration::from_turns(), get_hourly_rotpoints_at_temp(), calendar::INDEFINITELY_LONG_DURATION, rot, temperature_flag_to_highest_temperature(), and type.

Referenced by food_info().

◆ mitigate_damage()

void item::mitigate_damage ( damage_unit du) const

Assuming that specified du hit the armor, reduce du based on the item's resistance to the damage type.

This will never reduce du.amount below 0.

Definition at line 6371 of file item.cpp.

6372{
6373 const resistances res = resistances( *this );
6374 const float mitigation = res.get_effective_resist( du );
6375 du.amount -= mitigation;
6376 du.amount = std::max( 0.0f, du.amount );
6377}
float get_effective_resist(const damage_unit &du) const
Definition: damage.cpp:217

References damage_unit::amount, and resistances::get_effective_resist().

Referenced by Character::armor_absorb(), and character_funcs::is_bp_immune_to().

◆ mod_charges()

void item::mod_charges ( int  mod)

Modify the charges of this item, only use for items counted by charges! The item must have enough charges for this (>= quantity) and be counted by charges.

Parameters
modHow many charges should be removed.

Definition at line 9742 of file item.cpp.

9743{
9744 if( has_infinite_charges() ) {
9745 return;
9746 }
9747
9748 if( !count_by_charges() ) {
9749 debugmsg( "Tried to remove %s by charges, but item is not counted by charges.", tname() );
9750 } else if( mod < 0 && charges + mod < 0 ) {
9751 debugmsg( "Tried to remove charges that do not exist, removing maximum available charges instead." );
9752 charges = 0;
9753 } else if( mod > 0 && charges >= INFINITE_CHARGES - mod ) {
9754 charges = INFINITE_CHARGES - 1; // Highly unlikely, but finite charges should not become infinite.
9755 } else {
9756 charges += mod;
9757 }
9758}

References charges, count_by_charges(), debugmsg, has_infinite_charges(), INFINITE_CHARGES, and tname().

Referenced by throw_activity_actor::do_turn(), Character::eat(), fill_with(), player::reduce_charges(), and talk_effect_fun_t::set_u_buy_item().

◆ mod_damage() [1/2]

bool item::mod_damage ( int  qty)

same as other mod_damage, but uses DT_NULL as damage type.

Definition at line 6256 of file item.cpp.

6257{
6258 return mod_damage( qty, DT_NULL );
6259}

References DT_NULL, and mod_damage().

◆ mod_damage() [2/2]

bool item::mod_damage ( int  qty,
damage_type  dt 
)

Apply damage to const itemrained by min_damage and max_damage.

Parameters
qtymaximum amount by which to adjust damage (negative permissible)
dttype of damage which may be passed to on_damage callback
Returns
whether item should be destroyed

Definition at line 6234 of file item.cpp.

6235{
6236 bool destroy = false;
6237
6238 if( count_by_charges() ) {
6239 charges -= std::min( type->stack_size * qty / itype::damage_scale, charges );
6240 destroy |= charges == 0;
6241 }
6242
6243 if( qty > 0 ) {
6244 on_damage( qty, dt );
6245 }
6246
6247 if( !count_by_charges() ) {
6248 destroy |= damage_ + qty > max_damage();
6249
6250 damage_ = std::max( std::min( damage_ + qty, max_damage() ), min_damage() );
6251 }
6252
6253 return destroy;
6254}
void on_damage(int qty, damage_type dt)
Callback immediately before an item is damaged.
Definition: item.cpp:4550

References charges, count_by_charges(), damage_, itype::damage_scale, max_damage(), min_damage(), on_damage(), itype::stack_size, and type.

Referenced by Character::armor_absorb(), iuse::gun_repair(), inc_damage(), activity_handlers::make_zlave_finish(), mod_damage(), vehicle::mod_hp(), and repair_item_actor::repair().

◆ mod_energy()

units::energy item::mod_energy ( const units::energy qty)

Add or remove energy from a battery.

If adding the specified energy quantity would go over the battery's capacity fill the battery and ignore the remainder. If adding the specified energy quantity would reduce the battery's charge level below 0 do nothing and return how far below 0 it would have gone.

Parameters
qtyenergy quantity to add (can be negative)
Returns
0 valued energy quantity on success

Definition at line 575 of file item.cpp.

576{
577 if( !is_battery() ) {
578 debugmsg( "Tried to set energy of non-battery item" );
579 return 0_J;
580 }
581
582 units::energy val = energy_remaining() + qty;
583 if( val < 0_J ) {
584 return val;
585 } else if( val > type->battery->max_capacity ) {
586 energy = type->battery->max_capacity;
587 } else {
588 energy = val;
589 }
590 return 0_J;
591}

References itype::battery, debugmsg, energy, energy_remaining(), is_battery(), and type.

◆ mod_last_rot_check()

void item::mod_last_rot_check ( time_duration  processing_duration)

This is part of a workaround so that items don't rot away to nothing if the smoking rack is outside the reality bubble.

Parameters
processing_duration

Definition at line 5729 of file item.cpp.

5730{
5731 if( !has_own_flag( "PROCESSING" ) ) {
5732 debugmsg( "mod_last_rot_check called on non smoking item: %s", tname() );
5733 return;
5734 }
5735
5736 // Apply no rot while smoking
5737 last_rot_check += processing_duration;
5738}

References debugmsg, has_own_flag(), last_rot_check, and tname().

◆ mod_rot()

void item::mod_rot ( const time_duration val)
inline

Definition at line 864 of file item.h.

864 {
865 rot += val;
866 }

◆ mutations_from_wearing()

std::vector< trait_id > item::mutations_from_wearing ( const Character guy) const

Definition at line 9097 of file item.cpp.

9098{
9099 if( !is_relic() ) {
9100 return std::vector<trait_id> {};
9101 }
9102 std::vector<trait_id> muts;
9103
9104 for( const enchantment &ench : relic_data->get_enchantments() ) {
9105 for( const trait_id &mut : ench.get_mutations() ) {
9106 // this may not be perfectly accurate due to conditions
9107 muts.push_back( mut );
9108 }
9109 }
9110
9111 for( const trait_id &char_mut : guy.get_mutations() ) {
9112 for( auto iter = muts.begin(); iter != muts.end(); ) {
9113 if( char_mut == *iter ) {
9114 iter = muts.erase( iter );
9115 } else {
9116 ++iter;
9117 }
9118 }
9119 }
9120
9121 return muts;
9122}
std::vector< trait_id > get_mutations(bool include_hidden=true) const
Get the idents of all traits/mutations.

References Character::get_mutations(), is_relic(), and relic_data.

Referenced by Character::on_item_takeoff(), and Character::on_item_wear().

◆ needs_processing()

bool item::needs_processing ( ) const

Whether the item should be processed (by calling process).

Definition at line 8943 of file item.cpp.

8944{
8947 is_artifact() || is_food();
8948}
bool needs_processing() const
Whether the item should be processed (by calling process).
Definition: item.cpp:8943
bool is_artifact() const
Definition: item.cpp:6976
static const std::string flag_ETHEREAL_ITEM("ETHEREAL_ITEM")

References active, contents, item_contents::empty(), flag_ETHEREAL_ITEM(), flag_RADIO_ACTIVATION(), item_contents::front(), has_flag(), is_artifact(), is_container(), is_food(), and needs_processing().

Referenced by map::add_item(), vehicle::add_item(), submap::load(), map::make_active(), vehicle::make_active(), needs_processing(), liquid_handler::perform_liquid_transfer(), and Character::process_items().

◆ nname()

std::string item::nname ( const itype_id id,
unsigned int  quantity = 1 
)
static

Returns the translated item name for the item with given id.

The name is in the proper plural form as specified by the quantity parameter. This is roughly equivalent to creating an item instance and calling tname, however this function does not include strings like "(fresh)".

Definition at line 9943 of file item.cpp.

9944{
9945 return id->nname( quantity );
9946}

Referenced by act_vehicle_unload_fuel(), ammo_info(), veh_interact::calc_overview(), camp_car_description(), crafting::can_disassemble(), Character::can_eat(), player::craft_consume_tools(), harvest_list::describe(), veh_interact::display_details(), draw_caravan_items(), spellcasting_callback::draw_spell_info(), farm_action(), activity_handlers::fertilize_plot_do_turn(), final_info(), iexamine::fvat_empty(), plot_options::get_descriptions(), iexamine::get_seed_entries(), plot_options::get_zone_name_suggestion(), repair_item_actor::handle_components(), ammobelt_actor::info(), iexamine::keg(), ma_style_callback::key(), lcmatch_any(), mill_load_food(), iuse::multicooker(), vpart_info::name(), comp_selection< CompType >::nname(), parse_tags(), peek_related_recipe(), activity_handlers::plant_seed_finish(), iexamine::portable_structure(), iexamine::pour_into_keg(), vehicle::print_fuel_indicator(), vehicle::print_part_list(), iexamine::quern_examine(), crafting::query_tool_selection(), avatar_action::reload(), activity_handlers::repair_item_finish(), recipe::result_name(), vehicle::select_engine(), player::select_item_component(), talk_effect_fun_t::set_u_sell_item(), character_funcs::siphon(), smoker_load_food(), iexamine::smoker_options(), vehicle::start_engine(), tname(), tool_comp::to_string(), iexamine::tree_maple(), iexamine::tree_maple_tapped(), try_consume(), unfold_vehicle_iuse::use(), consume_drug_iuse::use(), sew_advanced_actor::use(), and vehicle::use_washing_machine().

◆ on_contents_changed()

void item::on_contents_changed ( )

◆ on_damage()

void item::on_damage ( int  qty,
damage_type  dt 
)

Callback immediately before an item is damaged.

Parameters
qtymaximum damage that will be applied (constrained by max_damage)
dttype of damage (or DT_NULL)

Definition at line 4550 of file item.cpp.

4551{
4552 if( is_corpse() && qty + damage_ >= max_damage() ) {
4554 }
4555}

References damage_, flag_PULPED(), is_corpse(), max_damage(), and set_flag().

Referenced by mod_damage(), and set_damage().

◆ on_drop() [1/2]

bool item::on_drop ( const tripoint pos)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
Returns
true if the item was destroyed during placement.

Definition at line 10008 of file item.cpp.

10009{
10010 return on_drop( pos, get_map() );
10011}
bool on_drop(const tripoint &pos)
Invokes item type's itype::drop_action.
Definition: item.cpp:10008

References get_map(), and on_drop().

Referenced by map::add_item_or_charges(), and on_drop().

◆ on_drop() [2/2]

bool item::on_drop ( const tripoint pos,
map map 
)

Invokes item type's itype::drop_action.

This function can change the item.

Parameters
posWhere is the item being placed. Note: the item isn't there yet.
mapA map object associated with that position.
Returns
true if the item was destroyed during placement.

Definition at line 10013 of file item.cpp.

10014{
10015 // dropping liquids, even currently frozen ones, on the ground makes them
10016 // dirty
10017 if( made_of( LIQUID ) && !m.has_flag( flag_LIQUIDCONT, pos ) &&
10018 !has_own_flag( "DIRTY" ) ) {
10019 set_flag( "DIRTY" );
10020 }
10021 avatar &you = get_avatar();
10022 you.flag_encumbrance();
10023 return type->drop_action && type->drop_action.call( you, *this, false, pos );
10024}
void flag_encumbrance()
Flag encumbrance for updating.
Definition: character.cpp:1760
static const std::string flag_LIQUIDCONT("LIQUIDCONT")
use_function drop_action
Action to take BEFORE the item is placed on map.
Definition: itype.h:928
int call(player &, item &, bool, const tripoint &) const
Definition: iuse.cpp:9865

References use_function::call(), itype::drop_action, Character::flag_encumbrance(), flag_LIQUIDCONT(), get_avatar(), map::has_flag(), has_own_flag(), LIQUID, made_of(), set_flag(), and type.

◆ on_pickup()

void item::on_pickup ( Character p)

Callback when a player starts carrying the item.

The item is already in the inventory and is called from there. This is not called when the item is added to the inventory from worn vector or weapon slot. The item is considered already carried.

Definition at line 4519 of file item.cpp.

4520{
4521 // Fake characters are used to determine pickup weight and volume
4522 if( p.is_fake() ) {
4523 return;
4524 }
4525 avatar &you = get_avatar();
4526 // TODO: artifacts currently only work with the player character
4527 if( &p == &you && type->artifact ) {
4528 g->add_artifact_messages( type->artifact->effects_carried );
4529 }
4530 // if game is loaded - don't want ownership assigned during char creation
4531 if( you.getID().is_valid() ) {
4533 }
4534 if( is_bucket_nonempty() ) {
4536 }
4537
4538 p.flag_encumbrance();
4539}
virtual bool is_fake() const
Returns true for non-real Creatures used temporarily; i.e.
Definition: creature.cpp:978
bool is_valid() const
Definition: character_id.h:19
bool spill_contents(const tripoint &pos)
void handle_pickup_ownership(Character &c)
Definition: item.cpp:4479
bool is_bucket_nonempty() const
Definition: item.cpp:6753

References itype::artifact, contents, Character::flag_encumbrance(), g, get_avatar(), Character::getID(), handle_pickup_ownership(), is_bucket_nonempty(), Creature::is_fake(), character_id::is_valid(), Character::pos(), item_contents::spill_contents(), and type.

Referenced by Character::i_add().

◆ on_takeoff()

void item::on_takeoff ( Character p)

Callback when a character takes off an item.

The item is still in the worn items vector but will be removed immediately after the function returns

Definition at line 4398 of file item.cpp.

4399{
4400 p.on_item_takeoff( *this );
4401
4402 if( is_sided() ) {
4404 }
4405
4406 // if power armor, no power_draw and active, shut down.
4407 if( type->can_use( "set_transformed" ) && active ) {
4408 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4409 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4410 if( actor == nullptr ) {
4411 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4412 return;
4413 }
4414 actor->bypass( *p.as_player(), *this, false, p.pos() );
4415 }
4416}
void on_item_takeoff(const item &it)
Called when an item is taken off.
Definition: character.cpp:9869
virtual player * as_player()
Definition: creature.h:122
bool set_side(side s)
Change the side on which the item is worn.
Definition: item.cpp:818
This is a iuse_transform used by items with transform dependencies.
Definition: iuse_actor.h:350
int bypass(player &p, item &it, bool t, const tripoint &pos) const
Hack: Bypasses normal checks to transform an item.
Definition: iuse_actor.cpp:985

References active, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), debugmsg, use_function::get_actor_ptr(), get_use(), is_sided(), Character::on_item_takeoff(), Character::pos(), set_side(), and type.

Referenced by Character::absorb_hit(), Character::i_rem(), and starting_clothes().

◆ on_wear()

void item::on_wear ( Character p)

Callback when a character starts wearing the item.

The item is already in the worn items vector and is called from there.

Definition at line 4300 of file item.cpp.

4301{
4302 if( is_sided() && get_side() == side::BOTH ) {
4303 if( has_flag( flag_SPLINT ) ) {
4305 if( ( covers( bodypart_id( "leg_l" ) ) && p.is_limb_broken( bodypart_id( "leg_r" ) ) &&
4306 !p.worn_with_flag( flag_SPLINT, bodypart_id( "leg_r" ) ) ) ||
4307 ( covers( bodypart_id( "arm_l" ) ) && p.is_limb_broken( bodypart_id( "arm_r" ) ) &&
4308 !p.worn_with_flag( flag_SPLINT, bodypart_id( "arm_r" ) ) ) ) {
4310 }
4311 } else if( has_flag( flag_POWERARMOR_MOD ) ) {
4312 // for power armor mods, wear on side with least mods
4313 std::vector< std::pair< body_part, int > > mod_parts;
4314 body_part bp = num_bp;
4315 bodypart_str_id bpid;
4316 int lhs = 0;
4317 int rhs = 0;
4318 for( std::size_t i = 0; i < static_cast< body_part >( num_bp ) ; ++i ) {
4319 bp = static_cast< body_part >( i );
4320 if( get_covered_body_parts().test( bp ) ) {
4321 mod_parts.emplace_back( bp, 0 );
4322 }
4323 }
4324 for( auto &elem : p.worn ) {
4325 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4326 bpid = convert_bp( mod_part.first );
4327 if( elem.get_covered_body_parts().test( mod_part.first ) &&
4328 elem.has_flag( flag_POWERARMOR_MOD ) ) {
4329 if( elem.is_sided() && elem.get_side() == bpid->part_side ) {
4330 mod_part.second++;
4331 continue;
4332 }
4333 mod_part.second++;
4334 }
4335 }
4336 }
4337 for( std::pair< body_part, int > &mod_part : mod_parts ) {
4338 bpid = convert_bp( mod_part.first );
4339 if( bpid->part_side == side::LEFT && mod_part.second > lhs ) {
4340 add_msg( _( "left" ) );
4341 lhs = mod_part.second;
4342 } else if( bpid->part_side == side::RIGHT && mod_part.second > rhs ) {
4343 add_msg( _( "right" ) );
4344 rhs = mod_part.second;
4345 }
4346 }
4347 set_side( ( lhs > rhs ) ? side::RIGHT : side::LEFT );
4348 } else {
4349 // for sided items wear the item on the side which results in least encumbrance
4350 int lhs = 0;
4351 int rhs = 0;
4353 const char_encumbrance_data left_enc = p.get_encumbrance( *this );
4354 for( const body_part bp : all_body_parts ) {
4355 lhs += left_enc.elems[bp].encumbrance;
4356 }
4357
4359 const char_encumbrance_data right_enc = p.get_encumbrance( *this );
4360 for( const body_part bp : all_body_parts ) {
4361 rhs += right_enc.elems[bp].encumbrance;
4362 }
4363
4364 set_side( lhs <= rhs ? side::LEFT : side::RIGHT );
4365 }
4366 }
4367
4368 if( type->can_use( "set_transformed" ) ) {
4369 bool transform = false;
4370 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
4371 ( this->get_use( "set_transformed" )->get_actor_ptr() );
4372 if( actor == nullptr ) {
4373 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
4374 return;
4375 }
4376 std::string transform_flag = actor->dependencies;
4377 for( const auto &elem : p.worn ) {
4378 if( elem.has_flag( transform_flag ) && elem.active != active ) {
4379 transform = true;
4380 }
4381 }
4382 if( transform && actor->restricted ) {
4383 actor->bypass( *p.as_player(), *this, false, p.pos() );
4384 }
4385 }
4386
4387 // TODO: artifacts currently only work with the player character
4388 if( &p == &get_avatar() && type->artifact ) {
4389 g->add_artifact_messages( type->artifact->effects_worn );
4390 }
4391 // if game is loaded - don't want ownership assigned during char creation
4392 if( get_avatar().getID().is_valid() ) {
4394 }
4395 p.on_item_wear( *this );
4396}
constexpr std::array< body_part, 12 > all_body_parts
Contains all valid body_part values in the order they are defined in.
Definition: bodypart.h:83
body_part
Definition: bodypart.h:40
@ num_bp
Definition: bodypart.h:53
bool worn_with_flag(const std::string &flag, const bodypart_id &bp=bodypart_str_id::NULL_ID()) const
Returns true if the player is wearing an item with the given flag.
Definition: character.cpp:3266
void on_item_wear(const item &it)
Called when an item is worn.
Definition: character.cpp:9854
bool is_limb_broken(const bodypart_id &limb) const
Returns true if the limb is broken.
Definition: character.cpp:1262
char_encumbrance_data get_encumbrance() const
Get encumbrance for all body parts.
Definition: character.cpp:3708
Just like the string_id, this is a wrapper for int based identifiers.
Definition: int_id.h:20
bool restricted
Whether the object can only be transformed externally.
Definition: iuse_actor.h:355
std::string dependencies
String defining flag needed on activating item.
Definition: iuse_actor.h:360
static const std::string flag_SPLINT("SPLINT")
void add_msg(std::string msg)
Definition: messages.cpp:910
side part_side
Definition: bodypart.h:127
std::array< encumbrance_data, num_bp > elems

References _, active, add_msg(), all_body_parts, itype::artifact, Creature::as_player(), BOTH, set_transformed_iuse::bypass(), itype::can_use(), convert_bp(), covers(), debugmsg, set_transformed_iuse::dependencies, char_encumbrance_data::elems, flag_POWERARMOR_MOD(), flag_SPLINT(), g, use_function::get_actor_ptr(), get_avatar(), get_covered_body_parts(), Character::get_encumbrance(), get_side(), get_use(), handle_pickup_ownership(), has_flag(), Character::is_limb_broken(), is_sided(), LEFT, num_bp, Character::on_item_wear(), body_part_type::part_side, Character::pos(), set_transformed_iuse::restricted, RIGHT, set_side(), body_part_set::test(), iexamine::transform(), type, Character::worn, and Character::worn_with_flag().

Referenced by starting_clothes().

◆ on_wield()

void item::on_wield ( player p,
int  mv = 0 
)

Callback when a player starts wielding the item.

The item is already in the weapon slot and is called from there.

Parameters
pplayer that has started wielding item
mvnumber of moves already spent wielding the weapon

Definition at line 4418 of file item.cpp.

4419{
4420 // TODO: artifacts currently only work with the player character
4421 if( &p == &get_avatar() && type->artifact ) {
4422 g->add_artifact_messages( type->artifact->effects_wielded );
4423 }
4424
4425 // weapons with bayonet/bipod or other generic "unhandiness"
4426 if( has_flag( flag_SLOW_WIELD ) && !is_gunmod() ) {
4427 float d = 32.0; // arbitrary linear scaling factor
4428 if( is_gun() ) {
4429 d /= std::max( p.get_skill_level( gun_skill() ), 1 );
4430 } else if( is_melee() ) {
4431 d /= std::max( p.get_skill_level( melee_skill() ), 1 );
4432 }
4433
4434 int penalty = get_var( "volume", volume() / units::legacy_volume_factor ) * d;
4435 p.moves -= penalty;
4436 mv += penalty;
4437 }
4438
4439 // firearms with a folding stock or tool/melee without collapse/retract iuse
4440 if( has_flag( flag_NEEDS_UNFOLD ) && !is_gunmod() ) {
4441 int penalty = 50; // 200-300 for guns, 50-150 for melee, 50 as fallback
4442 if( is_gun() ) {
4443 penalty = std::max( 0, 300 - p.get_skill_level( gun_skill() ) * 10 );
4444 } else if( is_melee() ) {
4445 penalty = std::max( 0, 150 - p.get_skill_level( melee_skill() ) * 10 );
4446 }
4447
4448 p.moves -= penalty;
4449 mv += penalty;
4450 }
4451
4452 std::string msg;
4453
4454 if( mv > 500 ) {
4455 msg = _( "It takes you an extremely long time to wield your %s." );
4456 } else if( mv > 250 ) {
4457 msg = _( "It takes you a very long time to wield your %s." );
4458 } else if( mv > 100 ) {
4459 msg = _( "It takes you a long time to wield your %s." );
4460 } else if( mv > 50 ) {
4461 msg = _( "It takes you several seconds to wield your %s." );
4462 } else {
4463 msg = _( "You wield your %s." );
4464 }
4465 // if game is loaded - don't want ownership assigned during char creation
4466 if( p.getID().is_valid() ) {
4468 }
4469 p.add_msg_if_player( m_neutral, msg, tname() );
4470
4471 if( !p.martial_arts_data->selected_is_none() ) {
4472 p.martial_arts_data->martialart_use_message( p );
4473 }
4474
4475 // Update encumbrance in case we were wearing it
4476 p.flag_encumbrance();
4477}
int moves
Definition: creature.h:582
void add_msg_if_player(const std::string &msg) const override
Definition: player.cpp:366
@ m_neutral
Definition: enums.h:267
static const std::string flag_NEEDS_UNFOLD("NEEDS_UNFOLD")
static const std::string flag_SLOW_WIELD("SLOW_WIELD")

References _, player::add_msg_if_player(), itype::artifact, Character::flag_encumbrance(), flag_NEEDS_UNFOLD(), flag_SLOW_WIELD(), g, get_avatar(), Character::get_skill_level(), get_var(), Character::getID(), gun_skill(), handle_pickup_ownership(), has_flag(), is_gun(), is_gunmod(), is_melee(), character_id::is_valid(), units::legacy_volume_factor, m_neutral, Character::martial_arts_data, melee_skill(), Creature::moves, tname(), type, and volume().

Referenced by character_funcs::try_wield_contents(), and avatar::wield().

◆ only_made_of()

bool item::only_made_of ( const std::set< material_id > &  mat_idents) const

Check we are made of only the materials (e.g.

false if we have one material not in the set or no materials at all).

Parameters
mat_identsSet of material ids.

Definition at line 6455 of file item.cpp.

6456{
6457 const std::vector<material_id> &mats = made_of();
6458 if( mats.empty() ) {
6459 return false;
6460 }
6461
6462 return std::all_of( mats.begin(), mats.end(), [&mat_idents]( const material_id & e ) {
6463 return mat_idents.count( e );
6464 } );
6465}

References made_of().

Referenced by salvage_actor::try_to_cut_up(), and salvage_actor::valid_to_cut_up().

◆ operator<()

bool item::operator< ( const item other) const

Definition at line 7165 of file item.cpp.

7166{
7167 const item_category &cat_a = get_category();
7168 const item_category &cat_b = other.get_category();
7169 if( cat_a != cat_b ) {
7170 return cat_a < cat_b;
7171 } else {
7172 const item *me = is_container() && !contents.empty() ? &contents.front() : this;
7173 const item *rhs = other.is_container() &&
7174 !other.contents.empty() ? &other.contents.front() : &other;
7175
7176 const itype *me_type = me->type;
7177 const itype *rhs_type = rhs->type;
7178 if( !me_type || !rhs_type ) {
7179 return !!me_type;
7180 }
7181
7182 if( me_type->get_id() == rhs_type->get_id() ) {
7183 if( me->is_money() ) {
7184 return me->charges > rhs->charges;
7185 }
7186 return me->charges < rhs->charges;
7187 } else {
7188 std::string n1 = me_type->nname( 1 );
7189 std::string n2 = rhs_type->nname( 1 );
7190 return localized_compare( n1, n2 );
7191 }
7192 }
7193}

References charges, contents, item_contents::empty(), item_contents::front(), get_category(), itype::get_id(), is_container(), is_money(), localized_compare, itype::nname(), other, and type.

◆ operator=() [1/2]

item & item::operator= ( const item )
default

◆ operator=() [2/2]

item & item::operator= ( item &&  )
default

◆ price()

int item::price ( bool  practical) const

Returns the monetary value of an item.

If practical is false, returns pre-cataclysm market value, otherwise returns approximate post-cataclysm value.

Definition at line 4929 of file item.cpp.

4930{
4931 int res = 0;
4932
4933 visit_items( [&res, practical]( const item * e ) {
4934 if( e->rotten() ) {
4935 // TODO: Special case things that stay useful when rotten
4936 return VisitResponse::NEXT;
4937 }
4938
4939 int child = units::to_cent( practical ? e->type->price_post : e->type->price );
4940 if( e->damage() > 0 ) {
4941 // maximal damage level is 4, maximal reduction is 40% of the value.
4942 child -= child * static_cast<double>( e->damage_level( 4 ) ) / 10;
4943 }
4944
4945 if( e->count_by_charges() || e->made_of( LIQUID ) ) {
4946 // price from json data is for default-sized stack
4947 child *= e->charges / static_cast<double>( e->type->stack_size );
4948
4949 } else if( e->magazine_integral() && e->ammo_remaining() && e->ammo_data() ) {
4950 // items with integral magazines may contain ammunition which can affect the price
4951 child += item( e->ammo_data(), calendar::turn, e->charges ).price( practical );
4952
4953 } else if( e->is_tool() && e->ammo_types().empty() && e->ammo_capacity() ) {
4954 // if tool has no ammo (e.g. spray can) reduce price proportional to remaining charges
4955 child *= e->ammo_remaining() / static_cast<double>( std::max( e->type->charges_default(), 1 ) );
4956 }
4957
4958 res += child;
4959 return VisitResponse::NEXT;
4960 } );
4961
4962 return res;
4963}
constexpr value_type to_cent(const quantity< value_type, money_in_cent_tag > &v)
Definition: units_money.h:44
units::money price
Value before cataclysm.
Definition: itype.h:985
units::money price_post
Value after cataclysm, dependent upon practical usages.
Definition: itype.h:987

References ammo_capacity(), ammo_data(), ammo_remaining(), ammo_types(), count_by_charges(), damage(), is_tool(), LIQUID, made_of(), magazine_integral(), NEXT, itype::price, itype::price_post, rotten(), units::to_cent(), type, and visitable< item >::visit_items().

Referenced by talk_function::bionic_install(), talk_function::bionic_remove(), defense_game::caravan(), draw_caravan_items(), talk_function::field_harvest(), final_info(), bionic_install_surgeon_preset::get_money_amount(), npc_trading::init_buying(), npc_trading::init_selling(), parse_tags(), talk_effect_fun_t::set_bulk_trade_accept(), npc::shop_restock(), npc::value(), npc::wants_to_buy(), and npc::wants_to_sell().

◆ process() [1/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 9618 of file item.cpp.

9620{
9621 const bool preserves = type->container && type->container->preserves;
9622 const bool seals = type->container && type->container->seals;
9623 std::vector<item *> removed_items;
9624 visit_items( [&]( item * it ) {
9625 if( preserves ) {
9626 // Simulate that the item has already "rotten" up to last_rot_check, but as item::rot
9627 // is not changed, the item is still fresh.
9629 }
9630 if( it->process_internal( carrier, pos, activate, seals, flag, weather_generator ) ) {
9631 removed_items.push_back( it );
9632 }
9633 return VisitResponse::NEXT;
9634 } );
9635 for( item *it : removed_items ) {
9636 if( it != this ) {
9637 remove_item( *it );
9638 }
9639 }
9640 return !removed_items.empty() && std::any_of( removed_items.begin(), removed_items.end(),
9641 [this]( const item * r ) {
9642 return r == this;
9643 } );
9644}
bool process_internal(player *carrier, const tripoint &pos, bool activate, bool seals, temperature_flag flag, const weather_manager &weather_generator)
Definition: item.cpp:9646
item & activate()
Filter converting instance to active state.
Definition: item.cpp:560

References activate(), itype::container, last_rot_check, NEXT, process_internal(), visitable< item >::remove_item(), calendar::turn, type, and visitable< item >::visit_items().

◆ process() [2/2]

bool item::process ( player carrier,
const tripoint pos,
bool  activate,
temperature_flag  flag = temperature_flag::TEMP_NORMAL 
)

This is called once each turn.

It's usually only useful for active items, but can be called for inactive items without problems. It is recursive, and calls process on any contained items.

Parameters
carrierThe player / npc that carries the item. This can be null when the item is not carried by anyone (laying on ground)!
posThe location of the item on the map, same system as player::pos used. If the item is carried, it should be the location of the carrier.
activateWhether the item should be activated (true), or processed as an active item.
Returns
true if the item has been destroyed by the processing. The caller should than delete the item wherever it was stored. Returns false if the item is not destroyed.

Definition at line 9612 of file item.cpp.

9614{
9615 return process( carrier, pos, activate, flag, get_weather() );
9616}
bool process(player *carrier, const tripoint &pos, bool activate, temperature_flag flag=temperature_flag::TEMP_NORMAL)
This is called once each turn.
Definition: item.cpp:9612
weather_manager & get_weather()
Definition: weather.cpp:64

References activate(), get_weather(), and process().

Referenced by map::add_item(), iuse::cable_attach(), drop_or_embed_projectile(), mattack::kamikaze(), process(), vehicle_part::process_contents(), Character::process_items(), and iuse::tow_attach().

◆ process_artifact()

void item::process_artifact ( player carrier,
const tripoint pos 
)

Process and apply artifact effects.

This should be called exactly once each turn, it may modify character stats (like speed, strength, ...), so call it after those have been reset.

Parameters
carrierThe character carrying the artifact, can be null.
posThe location of the artifact (should be the player location if carried).

Definition at line 9082 of file item.cpp.

9083{
9084 if( !is_artifact() ) {
9085 return;
9086 }
9087 // Artifacts are currently only useful for the player character, the messages
9088 // don't consider npcs. Also they are not processed when laying on the ground.
9089 // TODO: change game::process_artifact to work with npcs,
9090 // TODO: consider moving game::process_artifact here.
9091 if( carrier == &get_avatar() ) {
9092 g->process_artifact( *this, *carrier );
9093 }
9094}

References g, get_avatar(), and is_artifact().

Referenced by Character::process_turn().

◆ process_blackpowder_fouling()

bool item::process_blackpowder_fouling ( player carrier)
protected

Definition at line 9601 of file item.cpp.

9602{
9603 if( damage() < max_damage() && one_in( 2000 ) ) {
9605 if( carrier ) {
9606 carrier->add_msg_if_player( m_bad, _( "Your %s rusts due to blackpowder fouling." ), tname() );
9607 }
9608 }
9609 return false;
9610}
@ m_bad
Definition: enums.h:261

References _, player::add_msg_if_player(), damage(), DT_ACID, inc_damage(), m_bad, max_damage(), one_in(), and tname().

Referenced by process_internal().

◆ process_cable()

bool item::process_cable ( player carrier,
const tripoint pos 
)
protected

Definition at line 9383 of file item.cpp.

9384{
9385 if( carrier == nullptr ) {
9386 //reset_cable( carrier );
9387 return false;
9388 }
9389 std::string state = get_var( "state" );
9390 if( state == "solar_pack_link" || state == "solar_pack" ) {
9391 if( !carrier->has_item( *this ) || !carrier->worn_with_flag( "SOLARPACK_ON" ) ) {
9392 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9393 reset_cable( carrier );
9394 return false;
9395 }
9396 }
9397
9398 static const item_filter used_ups = [&]( const item & itm ) {
9399 return itm.get_var( "cable" ) == "plugged_in";
9400 };
9401
9402 if( state == "UPS" ) {
9403 if( !carrier->has_item( *this ) || !carrier->has_item_with( used_ups ) ) {
9404 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9405 for( item *used : carrier->items_with( used_ups ) ) {
9406 used->erase_var( "cable" );
9407 }
9408 reset_cable( carrier );
9409 return false;
9410 }
9411 }
9412 const std::optional<tripoint> source = get_cable_target( carrier, pos );
9413 if( !source ) {
9414 return false;
9415 }
9416 map &here = get_map();
9417 if( !here.veh_at( *source ) || ( source->z != g->get_levz() && !here.has_zlevels() ) ) {
9418 if( carrier->has_item( *this ) ) {
9419 carrier->add_msg_if_player( m_bad, _( "You notice the cable has come loose!" ) );
9420 }
9421 reset_cable( carrier );
9422 return false;
9423 }
9424
9425 int distance = rl_dist( pos, *source );
9426 int max_charges = type->maximum_charges();
9427 charges = max_charges - distance;
9428
9429 if( charges < 1 ) {
9430 if( carrier->has_item( *this ) ) {
9431 carrier->add_msg_if_player( m_bad, _( "The over-extended cable breaks loose!" ) );
9432 }
9433 reset_cable( carrier );
9434 }
9435
9436 return false;
9437}
void reset_cable(player *p)
Helper to bring a cable back to its initial state.
Definition: item.cpp:9439
std::optional< tripoint > get_cable_target(Character *p, const tripoint &pos) const
Gets the point (vehicle tile) the cable is connected to.
Definition: item.cpp:9363
bool has_zlevels() const
Definition: map.h:1635
std::vector< item * > items_with(const std::function< bool(const item &)> &filter)
Returns all items (including those within a container) matching the filter.
Definition: visitable.cpp:324
std::function< bool(const item &)> item_filter
Definition: game.h:119
int maximum_charges() const
Definition: itype.cpp:123

References _, player::add_msg_if_player(), charges, g, get_cable_target(), get_map(), get_var(), visitable< T >::has_item(), visitable< T >::has_item_with(), map::has_zlevels(), visitable< T >::items_with(), m_bad, itype::maximum_charges(), reset_cable(), rl_dist(), type, map::veh_at(), and Character::worn_with_flag().

Referenced by process_internal().

◆ process_corpse()

bool item::process_corpse ( player carrier,
const tripoint pos 
)
protected

Definition at line 9140 of file item.cpp.

9141{
9142 // some corpses rez over time
9143 if( corpse == nullptr || damage() >= max_damage() ) {
9144 return false;
9145 }
9146 if( corpse->zombify_into && rotten() ) {
9147 rot -= get_shelf_life();
9149 return false;
9150 }
9151 if( !ready_to_revive( pos ) ) {
9152 return false;
9153 }
9154 if( rng( 0, volume() / units::legacy_volume_factor ) > burnt && g->revive_corpse( pos, *this ) ) {
9155 if( carrier == nullptr ) {
9156 if( get_avatar().sees( pos ) ) {
9157 if( corpse->in_species( ROBOT ) ) {
9158 add_msg( m_warning, _( "A nearby robot has repaired itself and stands up!" ) );
9159 } else {
9160 add_msg( m_warning, _( "A nearby corpse rises and moves towards you!" ) );
9161 }
9162 }
9163 } else {
9164 if( corpse->in_species( ROBOT ) ) {
9165 carrier->add_msg_if_player( m_warning,
9166 _( "Oh dear god, a robot you're carrying has started moving!" ) );
9167 } else {
9168 carrier->add_msg_if_player( m_warning,
9169 _( "Oh dear god, a corpse you're carrying has started moving!" ) );
9170 }
9171 }
9172 // Destroy this corpse item
9173 return true;
9174 }
9175
9176 return false;
9177}
bool ready_to_revive(const tripoint &pos) const
Whether this corpse should revive now.
Definition: item.cpp:5973
@ m_warning
Definition: enums.h:264
static const species_id ROBOT("ROBOT")
mtype_id zombify_into
Definition: mtype.h:332
bool in_species(const species_id &spec) const
Definition: mtype.cpp:122

References _, add_msg(), player::add_msg_if_player(), burnt, corpse, damage(), g, get_avatar(), get_shelf_life(), mtype::in_species(), units::legacy_volume_factor, m_warning, max_damage(), ready_to_revive(), rng(), ROBOT, rotten(), volume(), and mtype::zombify_into.

Referenced by process_internal().

◆ process_extinguish()

bool item::process_extinguish ( player carrier,
const tripoint pos 
)
protected

Definition at line 9288 of file item.cpp.

9289{
9290 // checks for water
9291 bool extinguish = false;
9292 bool in_inv = carrier != nullptr && carrier->has_item( *this );
9293 bool submerged = false;
9294 bool precipitation = false;
9295 bool windtoostrong = false;
9296 bool in_veh = carrier != nullptr && carrier->in_vehicle;
9297 int windpower = get_weather().windspeed;
9298 switch( get_weather().weather_id->precip ) {
9300 precipitation = one_in( 100 );
9301 break;
9303 precipitation = one_in( 50 );
9304 break;
9306 precipitation = one_in( 10 );
9307 break;
9308 default:
9309 break;
9310 }
9311 map &here = get_map();
9312 if( in_inv && !in_veh && here.has_flag( flag_DEEP_WATER, pos ) ) {
9313 extinguish = true;
9314 submerged = true;
9315 }
9316 if( ( !in_inv && here.has_flag( flag_LIQUID, pos ) && !here.veh_at( pos ) ) ||
9317 ( precipitation && !g->is_sheltered( pos ) ) ) {
9318 extinguish = true;
9319 }
9320 if( in_inv && windpower > 5 && !g->is_sheltered( pos ) &&
9321 this->has_flag( flag_WIND_EXTINGUISH ) ) {
9322 windtoostrong = true;
9323 extinguish = true;
9324 }
9325 if( !extinguish ||
9326 ( in_inv && precipitation && carrier->primary_weapon().has_flag( flag_RAIN_PROTECT ) ) ) {
9327 return false; //nothing happens
9328 }
9329 if( carrier != nullptr ) {
9330 if( submerged ) {
9331 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by water." ), tname() );
9332 } else if( precipitation ) {
9333 carrier->add_msg_if_player( m_neutral, _( "Your %s is quenched by precipitation." ),
9334 tname() );
9335 } else if( windtoostrong ) {
9336 carrier->add_msg_if_player( m_neutral, _( "Your %s is blown out by the wind." ),
9337 tname() );
9338 }
9339 }
9340
9341 // cig dies out
9342 if( has_flag( flag_LITCIG ) ) {
9343 if( typeId() == itype_cig_lit ) {
9345 } else if( typeId() == itype_cigar_lit ) {
9347 } else { // joint
9349 }
9350 } else { // transform (lit) items
9351 if( type->tool->revert_to ) {
9352 convert( *type->tool->revert_to );
9353 } else {
9354 type->invoke( carrier != nullptr ? *carrier : get_avatar(), *this, pos, "transform" );
9355 }
9356
9357 }
9358 active = false;
9359 // Item remains
9360 return false;
9361}
bool in_vehicle
Definition: character.h:1573
item & primary_weapon()
Legacy code hack, don't use.
Definition: melee.cpp:166
bool has_flag(const std::string &flag, const tripoint &p) const
Definition: map.cpp:2374
static const itype_id itype_cigar_butt("cigar_butt")
static const itype_id itype_joint_roach("joint_roach")
static const itype_id itype_cig_butt("cig_butt")
static const std::string flag_LIQUID("LIQUID")
static const std::string flag_DEEP_WATER("DEEP_WATER")
static const itype_id itype_cigar_lit("cigar_lit")
static const std::string flag_WIND_EXTINGUISH("WIND_EXTINGUISH")
static const std::string flag_RAIN_PROTECT("RAIN_PROTECT")
static const itype_id itype_cig_lit("cig_lit")
int invoke(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:180

References _, active, player::add_msg_if_player(), convert(), flag_DEEP_WATER(), flag_LIQUID(), flag_LITCIG(), flag_RAIN_PROTECT(), flag_WIND_EXTINGUISH(), g, get_avatar(), get_map(), get_weather(), has_flag(), map::has_flag(), visitable< T >::has_item(), heavy, Character::in_vehicle, itype::invoke(), itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, light, m_neutral, one_in(), Character::primary_weapon(), tname(), itype::tool, type, typeId(), map::veh_at(), very_light, and weather_manager::windspeed.

Referenced by process_internal(), and process_litcig().

◆ process_fake_mill()

bool item::process_fake_mill ( player carrier,
const tripoint pos 
)
protected

Definition at line 9179 of file item.cpp.

9180{
9181 map &here = get_map();
9182 if( here.furn( pos ) != furn_str_id( "f_wind_mill_active" ) &&
9183 here.furn( pos ) != furn_str_id( "f_water_mill_active" ) ) {
9184 item_counter = 0;
9185 return true; //destroy fake mill
9186 }
9187 if( age() >= 6_hours || item_counter == 0 ) {
9189 birthday() ); //activate effects when timers goes to zero
9190 return true; //destroy fake mill item
9191 }
9192
9193 return false;
9194}
furn_id furn(const tripoint &p) const
Definition: map.cpp:1412
void mill_finalize(player &, const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5469

References age(), birthday(), map::furn(), get_avatar(), get_map(), item_counter, and iexamine::mill_finalize().

Referenced by process_internal().

◆ process_fake_smoke()

bool item::process_fake_smoke ( player carrier,
const tripoint pos 
)
protected

Definition at line 9196 of file item.cpp.

9197{
9198 map &here = get_map();
9199 if( here.furn( pos ) != furn_str_id( "f_smoking_rack_active" ) &&
9200 here.furn( pos ) != furn_str_id( "f_metal_smoking_rack_active" ) ) {
9201 item_counter = 0;
9202 return true; //destroy fake smoke
9203 }
9204
9205 if( age() >= 6_hours || item_counter == 0 ) {
9206 iexamine::on_smoke_out( pos, birthday() ); //activate effects when timers goes to zero
9207 return true; //destroy fake smoke when it 'burns out'
9208 }
9209
9210 return false;
9211}
void on_smoke_out(const tripoint &examp, const time_point &start_time)
Definition: iexamine.cpp:5785

References age(), birthday(), map::furn(), get_map(), item_counter, and iexamine::on_smoke_out().

Referenced by process_internal().

◆ process_internal()

bool item::process_internal ( player carrier,
const tripoint pos,
bool  activate,
bool  seals,
temperature_flag  flag,
const weather_manager weather_generator 
)
private

Definition at line 9646 of file item.cpp.

9649{
9650 if( has_flag( flag_ETHEREAL_ITEM ) ) {
9651 if( !has_var( "ethereal" ) ) {
9652 return true;
9653 }
9654 set_var( "ethereal", std::stoi( get_var( "ethereal" ) ) - 1 );
9655 const bool processed = std::stoi( get_var( "ethereal" ) ) <= 0;
9656 if( processed && carrier != nullptr ) {
9657 carrier->add_msg_if_player( _( "Your %s disappears!" ), tname() );
9658 }
9659 return processed;
9660 }
9661
9662 if( faults.count( fault_gun_blackpowder ) ) {
9663 return process_blackpowder_fouling( carrier );
9664 }
9665
9666 avatar &you = get_avatar();
9667 if( activate ) {
9668 return type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9669 }
9670 // How this works: it checks what kind of processing has to be done
9671 // (e.g. for food, for drying towels, lit cigars), and if that matches,
9672 // call the processing function. If that function returns true, the item
9673 // has been destroyed by the processing, so no further processing has to be
9674 // done.
9675 // Otherwise processing continues. This allows items that are processed as
9676 // food and as litcig and as ...
9677
9678 // Remaining stuff is only done for active items.
9679 if( !active ) {
9680 return false;
9681 }
9682
9683 if( !is_food() && item_counter > 0 ) {
9684 item_counter--;
9685 }
9686
9687 if( item_counter == 0 && type->countdown_action ) {
9688 type->countdown_action.call( carrier ? *carrier : you, *this, false, pos );
9689 if( type->countdown_destroy ) {
9690 return true;
9691 }
9692 }
9693
9694 map &here = get_map();
9695 for( const emit_id &e : type->emits ) {
9696 here.emit_field( pos, e );
9697 }
9698
9699 if( has_flag( flag_FAKE_SMOKE ) && process_fake_smoke( carrier, pos ) ) {
9700 return true;
9701 }
9702 if( has_flag( flag_FAKE_MILL ) && process_fake_mill( carrier, pos ) ) {
9703 return true;
9704 }
9705 if( is_corpse() && process_corpse( carrier, pos ) ) {
9706 return true;
9707 }
9708 if( has_flag( flag_WET ) && process_wet( carrier, pos ) ) {
9709 // Drying items are never destroyed, but we want to exit so they don't get processed as tools.
9710 return false;
9711 }
9712 if( has_flag( flag_LITCIG ) && process_litcig( carrier, pos ) ) {
9713 return true;
9714 }
9716 process_extinguish( carrier, pos ) ) {
9717 return false;
9718 }
9719 if( has_flag( flag_CABLE_SPOOL ) ) {
9720 // DO NOT process this as a tool! It really isn't!
9721 return process_cable( carrier, pos );
9722 }
9723 if( has_flag( flag_IS_UPS ) ) {
9724 // DO NOT process this as a tool! It really isn't!
9725 return process_UPS( carrier, pos );
9726 }
9727 if( is_tool() ) {
9728 return process_tool( carrier, pos );
9729 }
9730 // All foods that go bad have temperature
9731 if( ( is_food() || is_corpse() ) &&
9732 process_rot( seals, pos, carrier, flag, weather_generator ) ) {
9733 if( is_comestible() ) {
9734 here.rotten_item_spawn( *this, pos );
9735 }
9736 return true;
9737 }
9738
9739 return false;
9740}
bool process_fake_mill(player *carrier, const tripoint &pos)
Definition: item.cpp:9179
bool process_UPS(player *carrier, const tripoint &pos)
Definition: item.cpp:9456
bool process_corpse(player *carrier, const tripoint &pos)
Definition: item.cpp:9140
bool process_wet(player *carrier, const tripoint &pos)
Definition: item.cpp:9474
bool process_blackpowder_fouling(player *carrier)
Definition: item.cpp:9601
bool process_litcig(player *carrier, const tripoint &pos)
Definition: item.cpp:9213
bool process_extinguish(player *carrier, const tripoint &pos)
Definition: item.cpp:9288
bool process_fake_smoke(player *carrier, const tripoint &pos)
Definition: item.cpp:9196
bool process_tool(player *carrier, const tripoint &pos)
Definition: item.cpp:9487
bool process_cable(player *carrier, const tripoint &pos)
Definition: item.cpp:9383
void emit_field(const tripoint &pos, const emit_id &src, float mul=1.0f)
Runs one cycle of emission src which may result in propagation of fields.
Definition: map_field.cpp:1927
void rotten_item_spawn(const item &item, const tripoint &p)
Checks to see if the item that is rotting away generates a creature when it does.
Definition: map.cpp:7215
static const std::string flag_WATER_EXTINGUISH("WATER_EXTINGUISH")
static const std::string flag_CABLE_SPOOL("CABLE_SPOOL")
static const fault_id fault_gun_blackpowder("fault_gun_blackpowder")
static const std::string flag_IS_UPS("IS_UPS")
static const std::string flag_FAKE_MILL("FAKE_MILL")
static const std::string flag_FAKE_SMOKE("FAKE_SMOKE")
use_function countdown_action
Action to take when countdown expires.
Definition: itype.h:956
bool countdown_destroy
Is item destroyed after the countdown action is run?
Definition: itype.h:950
std::set< emit_id > emits
Fields to emit when item is in active state.
Definition: itype.h:931

References _, activate(), active, player::add_msg_if_player(), use_function::call(), itype::countdown_action, itype::countdown_destroy, map::emit_field(), itype::emits, fault_gun_blackpowder, faults, flag_CABLE_SPOOL(), flag_ETHEREAL_ITEM(), flag_FAKE_MILL(), flag_FAKE_SMOKE(), flag_IS_UPS(), flag_LITCIG(), flag_WATER_EXTINGUISH(), flag_WET(), flag_WIND_EXTINGUISH(), get_avatar(), get_map(), get_var(), has_flag(), has_var(), itype::invoke(), is_comestible(), is_corpse(), is_food(), is_tool(), item_counter, process_blackpowder_fouling(), process_cable(), process_corpse(), process_extinguish(), process_fake_mill(), process_fake_smoke(), process_litcig(), process_rot(), process_tool(), process_UPS(), process_wet(), map::rotten_item_spawn(), set_var(), tname(), and type.

Referenced by process().

◆ process_litcig()

bool item::process_litcig ( player carrier,
const tripoint pos 
)
protected

Definition at line 9213 of file item.cpp.

9214{
9215 if( !one_in( 10 ) ) {
9216 return false;
9217 }
9218 process_extinguish( carrier, pos );
9219 // process_extinguish might have extinguished the item already
9220 if( !active ) {
9221 return false;
9222 }
9223 map &here = get_map();
9224 // if carried by someone:
9225 if( carrier != nullptr ) {
9226 time_duration duration = 15_seconds;
9227 if( carrier->has_trait( trait_TOLERANCE ) ) {
9228 duration = 7_seconds;
9229 } else if( carrier->has_trait( trait_LIGHTWEIGHT ) ) {
9230 duration = 30_seconds;
9231 }
9232 carrier->add_msg_if_player( m_neutral, _( "You take a puff of your %s." ), tname() );
9233 if( has_flag( flag_TOBACCO ) ) {
9234 carrier->add_effect( effect_cig, duration );
9235 } else {
9236 carrier->add_effect( effect_weed_high, duration / 2 );
9237 }
9238 carrier->moves -= 15;
9239
9240 if( ( carrier->has_effect( effect_shakes ) && one_in( 10 ) ) ) {
9241 carrier->add_msg_if_player( m_bad, _( "Your shaking hand causes you to drop your %s." ),
9242 tname() );
9243 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9244 return true; // removes the item that has just been added to the map
9245 }
9246
9247 if( carrier->has_effect( effect_sleep ) ) {
9248 carrier->add_msg_if_player( m_bad, _( "You fall asleep and drop your %s." ),
9249 tname() );
9250 here.add_item_or_charges( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), *this );
9251 return true; // removes the item that has just been added to the map
9252 }
9253 } else {
9254 // If not carried by someone, but laying on the ground:
9255 if( item_counter % 5 == 0 ) {
9256 // lit cigarette can start fires
9257 if( here.flammable_items_at( pos ) ||
9258 here.has_flag( flag_FLAMMABLE, pos ) ||
9259 here.has_flag( flag_FLAMMABLE_ASH, pos ) ) {
9260 here.add_field( pos, fd_fire, 1 );
9261 }
9262 }
9263 }
9264
9265 // cig dies out
9266 if( item_counter == 0 ) {
9267 if( carrier != nullptr ) {
9268 carrier->add_msg_if_player( m_neutral, _( "You finish your %s." ), tname() );
9269 }
9270 if( typeId() == itype_cig_lit ) {
9272 } else if( typeId() == itype_cigar_lit ) {
9274 } else { // joint
9276 if( carrier != nullptr ) {
9277 carrier->add_effect( effect_weed_high, 1_minutes ); // one last puff
9278 here.add_field( pos + point( rng( -1, 1 ), rng( -1, 1 ) ), fd_weedsmoke, 2 );
9279 weed_msg( *carrier );
9280 }
9281 }
9282 active = false;
9283 }
9284 // Item remains
9285 return false;
9286}
void add_effect(const effect &eff, bool force=false, bool deferred=false)
Definition: creature.cpp:988
bool has_effect(const efftype_id &eff_id, body_part bp=num_bp) const
Check if creature has the matching effect.
Definition: creature.cpp:1187
bool add_field(const tripoint &p, const field_type_id &type_id, int intensity=INT_MAX, const time_duration &age=0_turns, bool hit_player=true)
Add field entry at point, or set intensity if present.
Definition: map.cpp:5507
item & add_item_or_charges(const tripoint &pos, item obj, bool overflow=true)
Adds an item to map tile or stacks charges.
Definition: map.cpp:4333
bool flammable_items_at(const tripoint &p, int threshold=0)
Checks if there are any flammable items on the tile.
Definition: map.cpp:2687
void weed_msg(player &p)
Handles the large variety of weed messages.
Definition: effect.cpp:78
field_type_id fd_fire
Definition: field_type.cpp:345
field_type_id fd_weedsmoke
Definition: field_type.cpp:368
static const efftype_id effect_weed_high("weed_high")
static const trait_id trait_TOLERANCE("TOLERANCE")
static const trait_id trait_LIGHTWEIGHT("LIGHTWEIGHT")
static const std::string flag_FLAMMABLE("FLAMMABLE")
static const efftype_id effect_cig("cig")
static const efftype_id effect_sleep("sleep")
static const std::string flag_FLAMMABLE_ASH("FLAMMABLE_ASH")
static const std::string flag_TOBACCO("TOBACCO")
static const efftype_id effect_shakes("shakes")
Definition: point.h:35

References _, active, Creature::add_effect(), map::add_field(), map::add_item_or_charges(), player::add_msg_if_player(), convert(), effect_cig, effect_shakes, effect_sleep, effect_weed_high, fd_fire, fd_weedsmoke, flag_FLAMMABLE(), flag_FLAMMABLE_ASH(), flag_TOBACCO(), map::flammable_items_at(), get_map(), Creature::has_effect(), has_flag(), map::has_flag(), Character::has_trait(), item_counter, itype_cig_butt, itype_cig_lit, itype_cigar_butt, itype_cigar_lit, itype_joint_roach, m_bad, m_neutral, Creature::moves, one_in(), process_extinguish(), rng(), tname(), trait_LIGHTWEIGHT, trait_TOLERANCE, typeId(), and weed_msg().

Referenced by process_internal().

◆ process_relic()

void item::process_relic ( Character carrier)

Definition at line 9124 of file item.cpp.

9125{
9126 if( !is_relic() ) {
9127 return;
9128 }
9129 std::vector<enchantment> active_enchantments;
9130
9131 for( const enchantment &ench : get_enchantments() ) {
9132 if( ench.is_active( carrier, *this ) ) {
9133 active_enchantments.emplace_back( ench );
9134 }
9135 }
9136
9137 relic_funcs::process_recharge( *this, carrier );
9138}
void process_recharge(item &itm, Character &carrier)
Definition: relic.cpp:449

References get_enchantments(), is_relic(), and relic_funcs::process_recharge().

Referenced by Character::process_turn().

◆ process_rot() [1/2]

bool item::process_rot ( bool  seals,
const tripoint pos,
player carrier,
temperature_flag  flag,
const weather_manager weather_generator 
)

Definition at line 8987 of file item.cpp.

8990{
8991 const time_point now = calendar::turn;
8992
8993 // if player debug menu'd the time backward it breaks stuff, just reset the
8994 // last_temp_check and last_rot_check in this case
8995 if( now - last_rot_check < 0_turns ) {
8996 last_rot_check = now;
8997 return false;
8998 }
8999
9000 // process rot at most once every 100_turns (10 min)
9001 // note we're also gated by item::processing_speed
9002 time_duration smallest_interval = 10_minutes;
9003
9004 units::temperature temp = units::from_fahrenheit( weather.get_temperature( pos ) );
9005 temp = clip_by_temperature_flag( temp, flag );
9006
9009
9010 if( now - time > 1_hours ) {
9011 // This code is for items that were left out of reality bubble for long time
9012
9013 const weather_generator &wgen = weather.get_cur_weather_gen();
9014 const unsigned int seed = g->get_seed();
9015 // It's a modifier, so we need to subtract 0_f
9016 units::temperature local_mod = units::from_fahrenheit( g->new_game
9017 ? 0
9018 : get_map().get_temperature( pos ) ) - 0_f;
9019
9020 // Process the past of this item since the last time it was processed
9021 while( now - time > 1_hours ) {
9022 // Get the environment temperature
9023 time_duration time_delta = std::min( 1_hours, now - 1_hours - time );
9024 time += time_delta;
9025
9026 //Use weather if above ground, use map temp if below
9027 units::temperature env_temperature_raw;
9028 if( pos.z >= 0 ) {
9029 tripoint_abs_ms location = tripoint_abs_ms( get_map().getabs( pos ) );
9030 units::temperature weather_temperature = wgen.get_weather_temperature( location, time,
9032 env_temperature_raw = weather_temperature + local_mod;
9033 } else {
9034 env_temperature_raw = units::from_fahrenheit( AVERAGE_ANNUAL_TEMPERATURE ) + local_mod;
9035 }
9036
9037 units::temperature env_temperature_clipped = clip_by_temperature_flag( env_temperature_raw, flag );
9038
9039 // Lookup table is in F
9040 int final_temperature_in_fahrenheit = static_cast<int>( std::round( units::to_fahrenheit<float>
9041 ( env_temperature_clipped ) ) );
9042
9043 // Calculate item rot
9044 rot += calc_rot( time, final_temperature_in_fahrenheit );
9046
9047 if( has_rotten_away() && carrier == nullptr && !seals ) {
9048 // No need to track item that will be gone
9049 return true;
9050 }
9051 }
9052 }
9053
9054 // Remaining <1 h from above
9055 // and items that are held near the player
9056 if( now - time > smallest_interval ) {
9057 int final_temperature_in_fahrenheit = static_cast<int>( std::round( units::to_fahrenheit<float>
9058 ( temp ) ) );
9059
9060 rot += calc_rot( now, final_temperature_in_fahrenheit );
9061 last_rot_check = now;
9062
9063 return has_rotten_away() && carrier == nullptr && !seals;
9064 }
9065 // If we're still here, mark how cold it is so we can apply tagtext to items
9066 // FIXME: this might cause issues with performance, move the comparision
9067 // directly to item::tname once #2250 lands
9068 if( temp <= temperatures::freezing ) {
9071 } else if( temp <= temperatures::root_cellar ) {
9074 } else {
9077 }
9078
9079 return false;
9080}
time_duration calc_rot(time_point time, int temp) const
Returns rot of the item since last rot calculation.
Definition: item.cpp:5659
bool has_rotten_away() const
Whether the item has enough rot that it should get removed.
Definition: item.cpp:8803
A point in the game time.
Definition: calendar.h:431
units::temperature get_weather_temperature(const tripoint_abs_ms &, const time_point &, const calendar_config &calendar_config, unsigned) const
coords::coord_point< tripoint, coords::origin::abs, coords::ms > tripoint_abs_ms
Definition: coordinates.h:486
static constexpr int AVERAGE_ANNUAL_TEMPERATURE
Average annual temperature in F used for climate, weather and temperature calculation.
static units::temperature clip_by_temperature_flag(units::temperature temperature, temperature_flag flag)
Definition: item.cpp:8964
static const std::string flag_VERY_COLD("VERY_COLD")
static const std::string flag_COLD("COLD")
calendar_config config
int seed(player *, item *, bool, const tripoint &)
Definition: iuse.cpp:6013
constexpr units::temperature freezing
constexpr units::temperature root_cellar
constexpr quantity< value_type, temperature_in_millidegree_celsius_tag > from_fahrenheit(const value_type v)
int z
Definition: point.h:138

References AVERAGE_ANNUAL_TEMPERATURE, calc_rot(), clip_by_temperature_flag(), calendar::config, flag_COLD(), flag_VERY_COLD(), temperatures::freezing, units::from_fahrenheit(), g, get_map(), weather_generator::get_weather_temperature(), has_rotten_away(), last_rot_check, temperatures::root_cellar, iuse::seed(), set_flag(), time, calendar::turn, unset_flag(), and tripoint::z.

◆ process_rot() [2/2]

bool item::process_rot ( const tripoint pos)

Update temperature for things like food Update rot for things that perish All items that rot also have temperature.

Parameters
sealsWether the item is in sealed container
posThe current position
carrierThe current carrier
flagto specify special temperature situations
weather_generatorweather manager, mostly for testing
Returns
true if the item is fully rotten and is ready to be removed

Definition at line 8959 of file item.cpp.

8960{
8961 return process_rot( false, pos, nullptr, temperature_flag::TEMP_NORMAL, get_weather() );
8962}

References get_weather(), process_rot(), and TEMP_NORMAL.

Referenced by actualize_rot(), process_internal(), and process_rot().

◆ process_tool()

bool item::process_tool ( player carrier,
const tripoint pos 
)
protected

Definition at line 9487 of file item.cpp.

9488{
9489 avatar &you = get_avatar();
9490 // items with iuse set_transformed which are restricted turn off if not attached to their dependency.
9491 if( type->can_use( "set_transformed" ) ) {
9492 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9493 ( this->get_use( "set_transformed" )->get_actor_ptr() );
9494 if( actor == nullptr ) {
9495 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9496 return false;
9497 }
9498 if( actor->restricted ) {
9499 if( !carrier ) {
9500 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9501 return false;
9502 } else {
9503 bool active = false;
9504 std::string transform_flag = actor->dependencies;
9505 for( const auto &elem : carrier->worn ) {
9506 if( elem.active && elem.has_flag( transform_flag ) ) {
9507 active = true;
9508 break;
9509 }
9510 }
9511 if( !active ) {
9512 actor->bypass( carrier != nullptr ? *carrier : you, *this, false, pos );
9513 return false;
9514 }
9515 }
9516 }
9517 }
9518
9519 int energy = 0;
9520 if( type->tool->turns_per_charge > 0 &&
9521 to_turn<int>( calendar::turn ) % type->tool->turns_per_charge == 0 ) {
9522 energy = std::max( ammo_required(), 1 );
9523
9524 } else if( type->tool->power_draw > 0 ) {
9525 // power_draw in mW / 1000000 to give kJ (battery unit) per second
9526 energy = type->tool->power_draw / 1000000;
9527 // energy_bat remainder results in chance at additional charge/discharge
9528 energy += x_in_y( type->tool->power_draw % 1000000, 1000000 ) ? 1 : 0;
9529 }
9530 energy -= ammo_consume( energy, pos );
9531
9532 // for power armor pieces, try to use power armor interface first.
9533 if( carrier && is_power_armor() && character_funcs::can_interface_armor( *carrier ) ) {
9534 if( carrier->use_charges_if_avail( itype_bio_armor, energy ) ) {
9535 energy = 0;
9536 }
9537 }
9538
9539 // for items in player possession if insufficient charges within tool try UPS
9540 if( carrier && ( has_flag( flag_USE_UPS ) ) ) {
9541 if( carrier->use_charges_if_avail( itype_UPS, energy ) ) {
9542 energy = 0;
9543 }
9544 }
9545
9546 // if insufficient available charges shutdown the tool
9547 if( energy > 0 ) {
9548 if( carrier ) {
9549 if( is_power_armor() ) {
9550 if( has_flag( flag_USE_UPS ) ) {
9551 carrier->add_msg_if_player( m_info, _( "You need a UPS or Bionic Power Interface to run the %s!" ),
9552 tname() );
9553 } else {
9554 carrier->add_msg_if_player( m_info, _( "You need a Bionic Power Interface to run the %s!" ),
9555 tname() );
9556 }
9557 } else if( has_flag( flag_USE_UPS ) ) {
9558 carrier->add_msg_if_player( m_info, _( "You need a UPS to run the %s!" ), tname() );
9559 }
9560 }
9561 if( carrier && type->can_use( "set_transform" ) ) {
9562 const set_transform_iuse *actor = dynamic_cast<const set_transform_iuse *>
9563 ( this->get_use( "set_transform" )->get_actor_ptr() );
9564 if( actor == nullptr ) {
9565 debugmsg( "iuse_actor type descriptor and actual type mismatch." );
9566 return false;
9567 }
9568 std::string transformed_flag = actor->flag;
9569 for( auto &elem : carrier->worn ) {
9570 if( elem.active && elem.has_flag( transformed_flag ) ) {
9571 if( !elem.type->can_use( "set_transformed" ) ) {
9572 debugmsg( "Expected set_transformed function" );
9573 return false;
9574 }
9575 const set_transformed_iuse *actor = dynamic_cast<const set_transformed_iuse *>
9576 ( elem.get_use( "set_transformed" )->get_actor_ptr() );
9577 if( actor == nullptr ) {
9578 debugmsg( "iuse_actor type descriptor and actual type mismatch" );
9579 return false;
9580 }
9581 actor->bypass( *carrier, elem, false, pos );
9582 }
9583 }
9584 }
9585
9586 // invoking the object can convert the item to another type
9587 const bool had_revert_to = type->tool->revert_to.has_value();
9588 type->invoke( carrier != nullptr ? *carrier : you, *this, pos );
9589 if( had_revert_to ) {
9590 deactivate( carrier );
9591 return false;
9592 } else {
9593 return true;
9594 }
9595 }
9596
9597 type->tick( carrier != nullptr ? *carrier : you, *this, pos );
9598 return false;
9599}
bool use_charges_if_avail(const itype_id &it, int quantity)
Definition: character.cpp:9654
item & deactivate(const Character *ch=nullptr, bool alert=true)
Filter converting this instance to the inactive type If the item is either inactive or cannot be deac...
Definition: item.cpp:543
This is a iuse_transform that changes a set of items with a specific flag.
Definition: iuse_actor.h:318
std::string flag
Flag string so we know what the heck we're transforming.
Definition: iuse_actor.h:328
static const itype_id itype_UPS("UPS")
static const itype_id itype_bio_armor("bio_armor")
bool can_interface_armor(const Character &who)
Check whether character has an active bionic capable of interfacing with power armor.
void tick(player &p, item &it, const tripoint &pos) const
Definition: itype.cpp:172

References _, active, player::add_msg_if_player(), ammo_consume(), ammo_required(), set_transformed_iuse::bypass(), character_funcs::can_interface_armor(), itype::can_use(), deactivate(), debugmsg, set_transformed_iuse::dependencies, energy, set_transform_iuse::flag, flag_USE_UPS(), use_function::get_actor_ptr(), get_avatar(), get_use(), has_flag(), itype::invoke(), is_power_armor(), itype_bio_armor, itype_UPS, m_info, set_transformed_iuse::restricted, itype::tick(), tname(), itype::tool, calendar::turn, type, Character::use_charges_if_avail(), Character::worn, and x_in_y().

Referenced by process_internal().

◆ process_UPS()

bool item::process_UPS ( player carrier,
const tripoint pos 
)
protected

Definition at line 9456 of file item.cpp.

9457{
9458 if( carrier == nullptr ) {
9459 erase_var( "cable" );
9460 active = false;
9461 return false;
9462 }
9463 bool has_connected_cable = carrier->has_item_with( []( const item & it ) {
9464 return it.active && it.has_flag( flag_CABLE_SPOOL ) && ( it.get_var( "state" ) == "UPS_link" ||
9465 it.get_var( "state" ) == "UPS" );
9466 } );
9467 if( !has_connected_cable ) {
9468 erase_var( "cable" );
9469 active = false;
9470 }
9471 return false;
9472}

References active, erase_var(), flag_CABLE_SPOOL(), get_var(), has_flag(), and visitable< T >::has_item_with().

Referenced by process_internal().

◆ process_wet()

bool item::process_wet ( player carrier,
const tripoint pos 
)
protected

Definition at line 9474 of file item.cpp.

9475{
9476 if( item_counter == 0 ) {
9477 if( is_tool() && type->tool->revert_to ) {
9478 convert( *type->tool->revert_to );
9479 }
9480 unset_flag( "WET" );
9481 active = false;
9482 }
9483 // Always return true so our caller will bail out instead of processing us as a tool.
9484 return true;
9485}

References active, convert(), is_tool(), item_counter, itype::tool, type, and unset_flag().

Referenced by process_internal().

◆ processing_speed()

int item::processing_speed ( ) const

The rate at which an item should be processed, in number of turns between updates.

Definition at line 8950 of file item.cpp.

8951{
8952 if( is_corpse() || is_food() || is_food_container() ) {
8953 return to_turns<int>( 10_minutes );
8954 }
8955 // Unless otherwise indicated, update every turn.
8956 return 1;
8957}

References is_corpse(), is_food(), and is_food_container().

Referenced by active_item_cache::add().

◆ put_in()

◆ qualities_info()

void item::qualities_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3231 of file item.cpp.

3233{
3234 auto name_quality = [&info]( const std::pair<quality_id, int> &q ) {
3235 std::string str;
3236 if( q.first == qual_JACK || q.first == qual_LIFT ) {
3237 str = string_format( _( "Has level <info>%1$d %2$s</info> quality and "
3238 "is rated at <info>%3$d</info> %4$s" ),
3239 q.second, q.first.obj().name,
3240 static_cast<int>( convert_weight( q.second * TOOL_LIFT_FACTOR ) ),
3241 weight_units() );
3242 } else {
3243 str = string_format( _( "Has level <info>%1$d %2$s</info> quality." ),
3244 q.second, q.first.obj().name );
3245 }
3246 info.emplace_back( "QUALITIES", "", str );
3247 };
3248
3249 if( parts->test( iteminfo_parts::QUALITIES ) ) {
3251 for( const std::pair<const quality_id, int> q : sorted_lex( type->qualities ) ) {
3252 name_quality( q );
3253 }
3254 }
3255
3257 contents.has_any_with( []( const item & e ) {
3258 return !e.type->qualities.empty();
3259 } ) ) {
3260
3261 info.emplace_back( "QUALITIES", "", _( "Contains items with qualities:" ) );
3262 std::map<quality_id, int, quality_id::LexCmp> most_quality;
3263 for( const item *e : contents.all_items_top() ) {
3264 for( const std::pair<const quality_id, int> &q : e->type->qualities ) {
3265 auto emplace_result = most_quality.emplace( q );
3266 if( !emplace_result.second &&
3267 most_quality.at( emplace_result.first->first ) < q.second ) {
3268 most_quality[ q.first ] = q.second;
3269 }
3270 }
3271 }
3272 for( const std::pair<const quality_id, int> &q : most_quality ) {
3273 name_quality( q );
3274 }
3275 }
3276}
bool has_any_with(const std::function< bool(const item &)> &filter) const
#define TOOL_LIFT_FACTOR
static const quality_id qual_JACK("JACK")
static const quality_id qual_LIFT("LIFT")

References _, item_contents::all_items_top(), contents, convert_weight(), item_contents::has_any_with(), info(), insert_separation_line(), qual_JACK, qual_LIFT, QUALITIES, itype::qualities, QUALITIES_CONTAINED, sorted_lex(), string_format(), iteminfo_query::test(), TOOL_LIFT_FACTOR, type, and weight_units().

Referenced by info().

◆ quality_of()

const std::map< quality_id, int > & item::quality_of ( ) const

The ids of all the qualities this contains.

Definition at line 6429 of file item.cpp.

6430{
6431 return type->qualities;
6432}

References itype::qualities, and type.

◆ reach_range()

int item::reach_range ( const Character guy) const

Max range of melee attack this weapon can be used for.

Accounts for character's abilities and installed gun mods. Guaranteed to be at least 1

Definition at line 5273 of file item.cpp.

5274{
5275 int res = 1;
5276
5277 if( has_flag( flag_REACH_ATTACK ) ) {
5278 res = has_flag( flag_REACH3 ) ? 3 : 2;
5279 }
5280
5281 // for guns consider any attached gunmods
5282 if( is_gun() && !is_gunmod() ) {
5283 for( const std::pair<const gun_mode_id, gun_mode> &m : gun_all_modes() ) {
5284 if( guy.is_npc() && m.second.flags.count( "NPC_AVOID" ) ) {
5285 continue;
5286 }
5287 if( m.second.melee() ) {
5288 res = std::max( res, m.second.qty );
5289 }
5290 }
5291 }
5292
5293 return std::max( 1, res );
5294}
virtual bool is_npc() const
Definition: creature.h:98

References flag_REACH3(), flag_REACH_ATTACK(), gun_all_modes(), has_flag(), is_gun(), is_gunmod(), and Creature::is_npc().

Referenced by avatar_action::autoattack(), fire(), npc::invalidate_range_cache(), Character::melee_attack(), npc_ai::melee_value(), npc::method_of_attack(), and target_handler::mode_reach().

◆ ready_to_revive()

bool item::ready_to_revive ( const tripoint pos) const

Whether this corpse should revive now.

Note that this function includes some randomness, the return value can differ on successive calls.

Parameters
posThe location of the item (see REVIVE_SPECIAL flag).

Definition at line 5973 of file item.cpp.

5974{
5975 if( !can_revive() ) {
5976 return false;
5977 }
5978 if( get_map().veh_at( pos ) ) {
5979 return false;
5980 }
5981 if( !calendar::once_every( 1_seconds ) ) {
5982 return false;
5983 }
5984 int age_in_hours = to_hours<int>( age() );
5985 age_in_hours -= static_cast<int>( static_cast<float>( burnt ) / ( volume() / 250_ml ) );
5986 if( damage_level( 4 ) > 0 ) {
5987 age_in_hours /= ( damage_level( 4 ) + 1 );
5988 }
5989 int rez_factor = 48 - age_in_hours;
5990 if( age_in_hours > 6 && ( rez_factor <= 0 || one_in( rez_factor ) ) ) {
5991 // If we're a special revival zombie, wait to get up until the player is nearby.
5992 const bool isReviveSpecial = has_flag( flag_REVIVE_SPECIAL );
5993 if( isReviveSpecial ) {
5994 const int distance = rl_dist( pos, get_player_character().pos() );
5995 if( distance > 3 ) {
5996 return false;
5997 }
5998 if( !one_in( distance + 1 ) ) {
5999 return false;
6000 }
6001 }
6002
6003 return true;
6004 }
6005 return false;
6006}
static const std::string flag_REVIVE_SPECIAL("REVIVE_SPECIAL")
bool once_every(const time_duration &event_frequency)
Predicate to handle rate-limiting.
Definition: calendar.cpp:490

References age(), burnt, can_revive(), damage_level(), flag_REVIVE_SPECIAL(), get_map(), get_player_character(), has_flag(), calendar::once_every(), one_in(), rl_dist(), and volume().

Referenced by process_corpse().

◆ reinforceable()

bool item::reinforceable ( ) const

Whether the item can be repaired beyond normal health.

Definition at line 6507 of file item.cpp.

6508{
6509 if( is_null() || has_flag( flag_NO_REPAIR ) ) {
6510 return false;
6511 }
6512
6513 // If a material is reinforceable, so are we
6514 const std::vector<const material_type *> &mats = made_of_types();
6515 return std::any_of( mats.begin(), mats.end(), []( const material_type * mt ) {
6516 return mt->reinforces();
6517 } );
6518}
static const std::string flag_NO_REPAIR("NO_REPAIR")

References flag_NO_REPAIR(), has_flag(), is_null(), and made_of_types().

Referenced by repair_item_actor::can_repair_target(), repair_item_actor::repair(), and repair_info().

◆ release_monster()

bool item::release_monster ( const tripoint target,
int  radius = 0 
)

Definition at line 9238 of file iuse.cpp.

9239{
9240 shared_ptr_fast<monster> new_monster = make_shared_fast<monster>();
9241 try {
9242 ::deserialize( *new_monster, get_var( "contained_json", "" ) );
9243 } catch( const std::exception &e ) {
9244 debugmsg( _( "Error restoring monster: %s" ), e.what() );
9245 return false;
9246 }
9247 if( !g->place_critter_around( new_monster, target, radius ) ) {
9248 return false;
9249 }
9250 erase_var( "contained_name" );
9251 erase_var( "contained_json" );
9252 erase_var( "name" );
9253 erase_var( "weight" );
9254 return true;
9255}
void deserialize(JsonIn &jsin)
std::shared_ptr< T > shared_ptr_fast
Definition: memory_fast.h:16

References _, debugmsg, deserialize(), erase_var(), g, and get_var().

Referenced by iuse::capture_monster_act(), and DefaultRemovePartHandler::spawn_animal_from_part().

◆ reload()

bool item::reload ( player u,
item_location  loc,
int  qty 
)

Reload item using ammo from location returning true if successful.

Parameters
uPlayer doing the reloading
locLocation of ammo to be reloaded
qtycaps reloading to this (or fewer) units

Definition at line 8119 of file item.cpp.

8120{
8121 if( qty <= 0 ) {
8122 debugmsg( "Tried to reload zero or less charges" );
8123 return false;
8124 }
8125 item *ammo = loc.get_item();
8126 if( ammo == nullptr || ammo->is_null() ) {
8127 debugmsg( "Tried to reload using non-existent ammo" );
8128 return false;
8129 }
8130
8131 item *container = nullptr;
8132 if( ammo->is_ammo_container() || ammo->is_container() ) {
8133 container = ammo;
8134 ammo = &ammo->contents.front();
8135 }
8136
8137 if( !is_reloadable_with( ammo->typeId() ) ) {
8138 return false;
8139 }
8140
8141 // limit quantity of ammo loaded to remaining capacity
8142 int limit = is_watertight_container()
8145
8146 if( ammo->ammo_type() == ammo_plutonium ) {
8147 limit = limit / PLUTONIUM_CHARGES + ( limit % PLUTONIUM_CHARGES != 0 );
8148 }
8149
8150 qty = std::min( qty, limit );
8151
8152 casings_handle( [&u]( item & e ) {
8153 return u.i_add_or_drop( e );
8154 } );
8155
8156 if( is_magazine() ) {
8157 qty = std::min( qty, ammo->charges );
8158
8159 if( is_ammo_belt() && type->magazine->linkage ) {
8160 if( !u.use_charges_if_avail( *type->magazine->linkage, qty ) ) {
8161 debugmsg( "insufficient linkages available when reloading ammo belt" );
8162 }
8163 }
8164
8165 item to_reload = *ammo;
8166 to_reload.charges = qty;
8167 ammo->charges -= qty;
8168 bool merged = false;
8169 for( item *it : contents.all_items_top() ) {
8170 if( it->merge_charges( to_reload ) ) {
8171 merged = true;
8172 break;
8173 }
8174 }
8175 if( !merged ) {
8176 put_in( to_reload );
8177 }
8178 } else if( is_watertight_container() ) {
8179 if( !ammo->made_of( LIQUID ) ) {
8180 debugmsg( "Tried to reload liquid container with non-liquid." );
8181 return false;
8182 }
8183 if( container ) {
8184 container->on_contents_changed();
8185 }
8186 fill_with( *ammo, qty );
8187 } else if( !magazine_integral() ) {
8188 // if we already have a magazine loaded prompt to eject it
8189 if( magazine_current() ) {
8190 //~ %1$s: magazine name, %2$s: weapon name
8191 std::string prompt = string_format( pgettext( "magazine", "Eject %1$s from %2$s?" ),
8192 magazine_current()->tname(), tname() );
8193
8194 // eject magazine to player inventory and try to dispose of it from there
8195 item &mag = u.i_add( *magazine_current() );
8196 if( !u.dispose_item( item_location( u, &mag ), prompt ) ) {
8197 u.remove_item( mag ); // user canceled so delete the clone
8198 return false;
8199 }
8201 }
8202
8203 put_in( *ammo );
8204 loc.remove_item();
8205 return true;
8206
8207 } else {
8208 if( ammo->has_flag( flag_SPEEDLOADER ) ) {
8209 curammo = ammo->contents.front().type;
8210 qty = std::min( qty, ammo->ammo_remaining() );
8211 ammo->ammo_consume( qty, tripoint_zero );
8212 charges += qty;
8213 } else if( ammo->ammo_type() == ammo_plutonium ) {
8214 curammo = ammo->type;
8215 ammo->charges -= qty;
8216
8217 // any excess is wasted rather than overfilling the item
8218 charges += qty * PLUTONIUM_CHARGES;
8219 charges = std::min( charges, ammo_capacity() );
8220 } else {
8221 curammo = ammo->type;
8222 qty = std::min( qty, ammo->charges );
8223 ammo->charges -= qty;
8224 charges += qty;
8225 }
8226 }
8227
8228 if( ammo->charges == 0 && !ammo->has_flag( flag_SPEEDLOADER ) ) {
8229 if( container != nullptr ) {
8230 container->remove_item( container->contents.front() );
8231 u.inv.restack( u ); // emptied containers do not stack with non-empty ones
8232 } else {
8233 loc.remove_item();
8234 }
8235 }
8236 return true;
8237}
item & i_add(item it, bool should_stack=true)
Definition: character.cpp:2265
bool i_add_or_drop(item &it, int qty=1)
Sets invlet and adds to inventory if possible, drops otherwise, returns true if either succeeded.
Definition: character.cpp:2405
virtual bool dispose_item(item_location &&obj, const std::string &prompt=std::string())
Drop, wear, stash or otherwise try to dispose of an item consuming appropriate moves.
Definition: character.cpp:7267
void restack(player &p)
Definition: inventory.cpp:399
item * get_item()
Gets the selected item or nullptr.
void remove_item()
Removes the selected item from the game.
void fill_with(item &liquid, int amount=INFINITE_CHARGES)
Fill item with liquid up to its capacity.
Definition: item.cpp:8576
bool is_ammo_belt() const
Definition: item.cpp:6575
static constexpr int PLUTONIUM_CHARGES
static const ammotype ammo_plutonium("plutonium")
static const std::string flag_SPEEDLOADER("SPEEDLOADER")
@ prompt
Definition: pickup.h:30
static constexpr tripoint tripoint_zero
Definition: point.h:259

References item_contents::all_items_top(), ammo_capacity(), ammo_consume(), ammo_plutonium, ammo_remaining(), ammo_type(), casings_handle(), charges, contents, curammo, debugmsg, Character::dispose_item(), fill_with(), flag_SPEEDLOADER(), item_contents::front(), item_location::get_item(), get_remaining_capacity_for_liquid(), has_flag(), Character::i_add(), Character::i_add_or_drop(), Character::inv, is_ammo_belt(), is_ammo_container(), is_container(), is_magazine(), is_null(), is_reloadable_with(), is_watertight_container(), LIQUID, made_of(), itype::magazine, magazine_current(), magazine_integral(), on_contents_changed(), pgettext(), PLUTONIUM_CHARGES, pickup::prompt, put_in(), item_location::remove_item(), visitable< item >::remove_item(), visitable< T >::remove_item(), inventory::restack(), string_format(), tname(), tripoint_zero, type, typeId(), and Character::use_charges_if_avail().

Referenced by veh_interact::complete_vehicle(), npc::do_reload(), ranged::fire_gun(), and activity_handlers::reload_finish().

◆ remove_old_owner()

void item::remove_old_owner ( ) const
inline

Definition at line 2026 of file item.h.

2026 {
2028 }

References string_id< faction >::NULL_ID().

Referenced by talk_function::drop_stolen_item(), and validate_ownership().

◆ remove_owner()

void item::remove_owner ( ) const
inline

Definition at line 2033 of file item.h.

2033 {
2035 }

References string_id< faction >::NULL_ID().

Referenced by validate_ownership().

◆ repair_info()

void item::repair_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3156 of file item.cpp.

3158{
3160 return;
3161 }
3163 const std::vector<itype_id> &rep = sorted_lex( repaired_with() );
3164 if( !rep.empty() ) {
3165 info.emplace_back( "DESCRIPTION", string_format( _( "<bold>Repair</bold> using %s." ),
3166 enumerate_as_string( rep.begin(), rep.end(), []( const itype_id & e ) {
3167 return nname( e );
3169 if( reinforceable() ) {
3170 info.emplace_back( "DESCRIPTION", _( "* This item can be <good>reinforced</good>." ) );
3171 }
3172 } else {
3173 info.emplace_back( "DESCRIPTION", _( "* This item is <bad>not repairable</bad>." ) );
3174 }
3175}
bool reinforceable() const
Whether the item can be repaired beyond normal health.
Definition: item.cpp:6507
const std::set< itype_id > & repaired_with() const
If possible to repair this item what tools could potentially be used for this purpose?
Definition: item.cpp:6365

References _, DESCRIPTION_REPAIREDWITH, enumerate_as_string(), info(), insert_separation_line(), or_, reinforceable(), repaired_with(), sorted_lex(), string_format(), and iteminfo_query::test().

Referenced by info().

◆ repaired_with()

const std::set< itype_id > & item::repaired_with ( ) const

If possible to repair this item what tools could potentially be used for this purpose?

Definition at line 6365 of file item.cpp.

6366{
6367 static std::set<itype_id> no_repair;
6368 return has_flag( flag_NO_REPAIR ) ? no_repair : type->repair;
6369}
std::set< itype_id > repair
Damage scale compared to the old float damage value.
Definition: itype.h:1011

References flag_NO_REPAIR(), has_flag(), itype::repair, and type.

Referenced by repair_info().

◆ reset_cable()

void item::reset_cable ( player p)

Helper to bring a cable back to its initial state.

Definition at line 9439 of file item.cpp.

9440{
9441 int max_charges = type->maximum_charges();
9442
9443 set_var( "state", "attach_first" );
9444 erase_var( "source_x" );
9445 erase_var( "source_y" );
9446 erase_var( "source_z" );
9447 active = false;
9448 charges = max_charges;
9449
9450 if( p != nullptr ) {
9451 p->add_msg_if_player( m_info, _( "You reel in the cable." ) );
9452 p->moves -= charges * 10;
9453 }
9454}

References _, active, player::add_msg_if_player(), charges, erase_var(), m_info, itype::maximum_charges(), Creature::moves, set_var(), and type.

Referenced by process_cable().

◆ rotten()

◆ serialize()

void item::serialize ( JsonOut json) const

Definition at line 2391 of file savegame_json.cpp.

2392{
2393 io::JsonObjectOutputArchive archive( json );
2394 const_cast<item *>( this )->io( archive );
2395 if( !contents.empty() ) {
2396 json.member( "contents", contents );
2397 }
2398}
void member(const std::string &name)
Definition: json.cpp:2235
Output archive matching the input archive JsonObjectInputArchive.
Definition: cata_io.h:351

References contents, item_contents::empty(), io(), and JsonOut::member().

Referenced by contain_monster().

◆ set_age()

void item::set_age ( const time_duration age)

Definition at line 10031 of file item.cpp.

10032{
10034}
void set_birthday(const time_point &bday)
Definition: item.cpp:10052

References age(), set_birthday(), and calendar::turn.

Referenced by burn(), iuse::firecracker_pack(), iuse::fish_trap(), iexamine::fvat_empty(), vehicle::operate_planter(), and map::process_fields_in_submap().

◆ set_birthday()

void item::set_birthday ( const time_point bday)

Definition at line 10052 of file item.cpp.

10053{
10054 this->bday = std::max( calendar::turn_zero, bday );
10055}

References bday, and calendar::turn_zero.

Referenced by editmap::edit_itm(), retroactively_fill_from_funnel(), set_age(), and debug_menu::wishitem().

◆ set_cached_tool_selections()

void item::set_cached_tool_selections ( const std::vector< comp_selection< tool_comp > > &  selections)

Definition at line 10133 of file item.cpp.

10134{
10135 assert( craft_data_ );
10136 craft_data_->cached_tool_selections = selections;
10137}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_countdown()

void item::set_countdown ( int  num_turns)

Sets time until activation for an item that will self-activate in the future.

Definition at line 8611 of file item.cpp.

8612{
8613 if( num_turns < 0 ) {
8614 debugmsg( "Tried to set a negative countdown value %d.", num_turns );
8615 return;
8616 }
8617 if( !ammo_types().empty() ) {
8618 debugmsg( "Tried to set countdown on an item with ammo." );
8619 return;
8620 }
8621 charges = num_turns;
8622}

References ammo_types(), charges, and debugmsg.

Referenced by iuse_transform::use().

◆ set_damage()

item & item::set_damage ( int  qty)

Filter setting damage constrained by min_damage and max_damage.

Note
this method does not invoke the on_damage callback
Returns
same instance to allow method chaining

Definition at line 717 of file item.cpp.

718{
719 on_damage( qty - damage_, DT_TRUE );
720 damage_ = std::max( std::min( qty, max_damage() ), min_damage() );
721 return *this;
722}

References damage_, DT_TRUE, max_damage(), min_damage(), and on_damage().

Referenced by mdeath::broken(), editmap::edit_itm(), iuse::gun_repair(), Item_modifier::modify(), vehicle_part::properties_to_item(), repair_item_actor::repair(), game::save_cyborg(), vehicle::set_hp(), and map::spawn_an_item().

◆ set_favorite()

void item::set_favorite ( bool  favorite)

Definition at line 10105 of file item.cpp.

10106{
10107 is_favorite = favorite;
10108}

References is_favorite.

Referenced by advanced_inventory::display(), and inventory_column::set_stack_favorite().

◆ set_flag()

item & item::set_flag ( const std::string &  flag)

Idempotent filter setting an item specific flag.

Definition at line 5340 of file item.cpp.

5341{
5342 item_tags.insert( flag );
5343 return *this;
5344}
iterator insert(iterator, const value_type &value)
Definition: flat_set.h:151

References cata::flat_set< T, Compare, Data >::insert(), and item_tags.

Referenced by map::add_corpse(), ammo_set(), are_requirements_nearby(), iexamine::autodoc(), explosion_handler::ExplosionProcess::blast_tile(), butcher_cbm_item(), activity_handlers::butcher_finish(), butchery_quarter(), iuse::camera(), crafting::complete_disassemble(), recipe::create_byproducts(), Single_item_creator::create_single(), cycle_action(), game::dump_stats(), Character::eat(), heal_actor::finish_using(), basecamp::form_crafting_inventory(), inventory::form_from_map(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iuse_transform::info(), inherit_flags(), init_memory_card_with_random_stuff(), item(), Item_factory::migrate_item(), Item_modifier::modify(), explosion_handler::ExplosionProcess::move_entity(), iexamine::nanofab(), on_damage(), on_drop(), process_rot(), vehicle_part::properties_to_item(), iuse::radio_mod(), activity_handlers::reload_finish(), repair_item_actor::repair(), mattack::riotbot(), set_flag_recursive(), spell_effect::spawn_ethereal_item(), map::spawn_item(), starting_clothes(), starting_inv(), iuse::towel_common(), avatar_funcs::unload_item(), sew_advanced_actor::use(), unpack_actor::use(), iexamine::use_furn_fake_item(), and vehicle_part::vehicle_part().

◆ set_flag_recursive()

item & item::set_flag_recursive ( const std::string &  flag)

Idempotent filter recursively setting an item specific flag on this item and its components.

Definition at line 5352 of file item.cpp.

5353{
5354 set_flag( flag );
5355 for( item &comp : components ) {
5356 comp.set_flag_recursive( flag );
5357 }
5358 return *this;
5359}

References components, and set_flag().

◆ set_mtype()

void item::set_mtype ( const mtype m)

Sets the monster type associated with this item (corpse).

You must not pass a null pointer. TODO: change this to take a reference instead.

Definition at line 6660 of file item.cpp.

6661{
6662 // This is potentially dangerous, e.g. for corpse items, which *must* have a valid mtype pointer.
6663 if( m == nullptr ) {
6664 debugmsg( "setting item::corpse of %s to NULL", tname() );
6665 return;
6666 }
6667 corpse = m;
6668}

References corpse, debugmsg, and tname().

Referenced by iuse::blood_draw().

◆ set_next_failure_point()

void item::set_next_failure_point ( const player crafter)

Calculates and sets the next failure point for an in progress craft.

Causes a debugmsg if called on non-craft.

Parameters
crafterthe crafting player

Definition at line 904 of file crafting.cpp.

905{
906 if( !is_craft() ) {
907 debugmsg( "set_next_failure_point() called on non-craft '%s.' Aborting.", tname() );
908 return;
909 }
910
911 const int percent_left = 10000000 - item_counter;
912 const int failure_point_delta = crafter.crafting_success_roll( get_making() ) * percent_left;
913
914 craft_data_->next_failure_point = item_counter + failure_point_delta;
915}

References craft_data_, player::crafting_success_roll(), debugmsg, get_making(), is_craft(), item_counter, and tname().

Referenced by craft_command::create_in_progress_craft(), and handle_craft_failure().

◆ set_old_owner()

void item::set_old_owner ( const faction_id temp_owner)
inline

Definition at line 2023 of file item.h.

2023 {
2024 old_owner = temp_owner;
2025 }

Referenced by handle_pickup_ownership().

◆ set_owner() [1/2]

void item::set_owner ( const Character c)

Definition at line 1273 of file item.cpp.

1274{
1275 if( !c.get_faction() ) {
1276 debugmsg( "item::set_owner() Character %s has no valid faction", c.disp_name() );
1277 return;
1278 }
1279 owner = c.get_faction()->id;
1280}

References c, debugmsg, and owner.

◆ set_owner() [2/2]

◆ set_relative_rot()

void item::set_relative_rot ( double  val)

Set current item rot relative to shelf life (no-op if item does not spoil)

Definition at line 5547 of file item.cpp.

5548{
5549 if( goes_bad() ) {
5550 rot = get_shelf_life() * val;
5551 // calc_rot uses last_rot_check (when it's not turn_zero) instead of bday.
5552 // this makes sure the rotting starts from now, not from bday.
5553 // if this item is the result of smoking or milling don't do this, we want to start from bday.
5556 }
5557 }
5558}
static const std::string flag_PROCESSING_RESULT("PROCESSING_RESULT")

References flag_PROCESSING_RESULT(), get_shelf_life(), goes_bad(), has_flag(), last_rot_check, and calendar::turn.

Referenced by complete_craft(), fill_with(), item(), and iexamine::keg().

◆ set_rot()

void item::set_rot ( time_duration  val)

Definition at line 5560 of file item.cpp.

5561{
5562 rot = val;
5563}

◆ set_side()

bool item::set_side ( side  s)

Change the side on which the item is worn.

Returns false if the item is not sided

Definition at line 818 of file item.cpp.

819{
820 if( !is_sided() ) {
821 return false;
822 }
823
824 if( s == side::BOTH ) {
825 erase_var( "lateral" );
826 } else {
827 set_var( "lateral", static_cast<int>( s ) );
828 }
829
830 return true;
831}

References BOTH, erase_var(), is_sided(), and set_var().

Referenced by on_takeoff(), on_wear(), and swap_side().

◆ set_snippet()

void item::set_snippet ( const snippet_id id)

Set the snippet text (description) of this specific item, using the snippet library.

See also
snippet_library.

Definition at line 8687 of file item.cpp.

8688{
8689 if( is_null() ) {
8690 return;
8691 }
8692 if( !id.is_valid() ) {
8693 debugmsg( "there's no snippet with id %s", id.str() );
8694 return;
8695 }
8696 snip_id = id;
8697}

References debugmsg, base_camps::id, is_null(), and snip_id.

Referenced by profession::items().

◆ set_tools_to_continue()

void item::set_tools_to_continue ( bool  value)

Definition at line 10121 of file item.cpp.

10122{
10123 assert( craft_data_ );
10124 craft_data_->tools_to_continue = value;
10125}

References craft_data_.

Referenced by craft_command::create_in_progress_craft().

◆ set_var() [1/6]

void item::set_var ( const std::string &  name,
const std::string &  value 
)

Definition at line 1059 of file item.cpp.

1060{
1061 item_vars[name] = value;
1062}

References item_vars, and om_direction::name().

◆ set_var() [2/6]

void item::set_var ( const std::string &  name,
const tripoint value 
)

Definition at line 1042 of file item.cpp.

1043{
1044 item_vars[name] = string_format( "%d,%d,%d", value.x, value.y, value.z );
1045}
int y
Definition: point.h:137
int x
Definition: point.h:136

References item_vars, om_direction::name(), string_format(), tripoint::x, tripoint::y, and tripoint::z.

◆ set_var() [3/6]

void item::set_var ( const std::string &  name,
double  value 
)

Definition at line 1028 of file item.cpp.

1029{
1030 item_vars[name] = string_format( "%f", value );
1031}

References item_vars, om_direction::name(), and string_format().

◆ set_var() [4/6]

◆ set_var() [5/6]

void item::set_var ( const std::string &  name,
long long  value 
)

Definition at line 1011 of file item.cpp.

1012{
1013 std::ostringstream tmpstream;
1014 tmpstream.imbue( std::locale::classic() );
1015 tmpstream << value;
1016 item_vars[name] = tmpstream.str();
1017}

References item_vars, and om_direction::name().

◆ set_var() [6/6]

void item::set_var ( const std::string &  name,
long  value 
)

Definition at line 1020 of file item.cpp.

1021{
1022 std::ostringstream tmpstream;
1023 tmpstream.imbue( std::locale::classic() );
1024 tmpstream << value;
1025 item_vars[name] = tmpstream.str();
1026}

References item_vars, and om_direction::name().

◆ sight_dispersion()

int item::sight_dispersion ( ) const

Get lowest dispersion of either integral or any attached sights.

Definition at line 7269 of file item.cpp.

7270{
7271 if( !is_gun() ) {
7272 return 0;
7273 }
7274
7275 int res = has_flag( flag_DISABLE_SIGHTS ) ? 90 : type->gun->sight_dispersion;
7276
7277 for( const item *e : gunmods() ) {
7278 const islot_gunmod &mod = *e->type->gunmod;
7279 if( mod.sight_dispersion < 0 || mod.aim_speed < 0 ) {
7280 continue; // skip gunmods which don't provide a sight
7281 }
7282 res = std::min( res, mod.sight_dispersion );
7283 }
7284
7285 return res;
7286}

References flag_DISABLE_SIGHTS(), itype::gun, gunmods(), has_flag(), is_gun(), and type.

Referenced by ranged::get_aim_types(), target_ui::panel_recoil(), print_aim(), and target_ui::run().

◆ simulate_burn()

float item::simulate_burn ( fire_data frd) const

Calculate all burning calculations, but don't actually apply them to item.

DO apply them to fire_data argument, though.

Returns
Amount of "burn" that would be applied to the item.

Definition at line 8239 of file item.cpp.

8240{
8241 const std::vector<material_id> &mats = made_of();
8242 float smoke_added = 0.0f;
8243 float time_added = 0.0f;
8244 float burn_added = 0.0f;
8245 const units::volume vol = base_volume();
8246 const int effective_intensity = frd.contained ? 3 : frd.fire_intensity;
8247 for( const material_id &m : mats ) {
8248 const mat_burn_data &bd = m.obj().burn_data( effective_intensity );
8249 if( bd.immune ) {
8250 // Made to protect from fire
8251 return 0.0f;
8252 }
8253
8254 // If fire is contained, burn rate is independent of volume
8255 if( frd.contained || bd.volume_per_turn == 0_ml ) {
8256 time_added += bd.fuel;
8257 smoke_added += bd.smoke;
8258 burn_added += bd.burn;
8259 } else {
8260 double volume_burn_rate = to_liter( bd.volume_per_turn ) / to_liter( vol );
8261 time_added += bd.fuel * volume_burn_rate;
8262 smoke_added += bd.smoke * volume_burn_rate;
8263 burn_added += bd.burn * volume_burn_rate;
8264 }
8265 }
8266
8267 // Liquids that don't burn well smother fire well instead
8268 if( made_of( LIQUID ) && time_added < 200 ) {
8269 time_added -= rng( 400.0 * to_liter( vol ), 1200.0 * to_liter( vol ) );
8270 } else if( mats.size() > 1 ) {
8271 // Average the materials
8272 time_added /= mats.size();
8273 smoke_added /= mats.size();
8274 burn_added /= mats.size();
8275 } else if( mats.empty() ) {
8276 // Non-liquid items with no specified materials will burn at moderate speed
8277 burn_added = 1;
8278 }
8279
8280 if( count_by_charges() ) {
8281 int stack_burnt = rng( type->stack_size / 2, type->stack_size );
8282 time_added *= stack_burnt;
8283 smoke_added *= stack_burnt;
8284 burn_added *= stack_burnt;
8285 }
8286
8287 frd.fuel_produced += time_added;
8288 frd.smoke_produced += smoke_added;
8289 return burn_added;
8290}
constexpr double to_liter(const volume &v)
Definition: units_volume.h:43
int fire_intensity
Current intensity of the fire.
Definition: fire.h:25
float fuel_produced
Fuel contributed by each burning item this turn is summed here.
Definition: fire.h:29
float smoke_produced
Smoke produced by each burning item this turn is summed here.
Definition: fire.h:27
bool contained
The fire is contained and burned for fuel intentionally.
Definition: fire.h:31
float smoke
Smoke produced per tick when this material burns.
Definition: fire.h:54
float burn
Volume of material destroyed per tick when this material burns.
Definition: fire.h:56

References base_volume(), mat_burn_data::burn, fire_data::contained, count_by_charges(), fire_data::fire_intensity, mat_burn_data::fuel, fire_data::fuel_produced, mat_burn_data::immune, LIQUID, made_of(), rng(), mat_burn_data::smoke, fire_data::smoke_produced, itype::stack_size, units::to_liter(), type, and mat_burn_data::volume_per_turn.

Referenced by burn(), and try_fuel_fire().

◆ spill_contents() [1/2]

bool item::spill_contents ( Character c)

Unloads the item's contents.

Parameters
cCharacter who receives the contents. If c is the player, liquids will be handled, otherwise they will be spilled.
Returns
If the item is now empty.

Definition at line 7067 of file item.cpp.

7068{
7069 if( !is_container() || is_container_empty() ) {
7070 return true;
7071 }
7072
7073 if( c.is_npc() ) {
7074 return spill_contents( c.pos() );
7075 }
7076
7079
7080 return true;
7081}
void handle_liquid_or_spill(Character &guy)
bool spill_contents(Character &c)
Unloads the item's contents.
Definition: item.cpp:7067

References c, contents, item_contents::handle_liquid_or_spill(), is_container(), is_container_empty(), on_contents_changed(), and spill_contents().

Referenced by drop_or_embed_projectile(), pickup::handle_spillable_contents(), Character::i_rem_keep_contents(), pick_one_up(), smash(), and spill_contents().

◆ spill_contents() [2/2]

bool item::spill_contents ( const tripoint pos)

Unloads the item's contents.

Parameters
posPosition to dump the contents on.
Returns
If the item is now empty.

Definition at line 7083 of file item.cpp.

7084{
7085 if( !is_container() || is_container_empty() ) {
7086 return true;
7087 }
7088
7089 for( item *it : contents.all_items_top() ) {
7090 get_map().add_item_or_charges( pos, *it );
7091 }
7092
7094 return true;
7095}

References map::add_item_or_charges(), item_contents::all_items_top(), item_contents::clear_items(), contents, get_map(), is_container(), and is_container_empty().

◆ split()

item item::split ( int  qty)

Splits a count-by-charges item always leaving source item with minimum of 1 charge.

Parameters
qtynumber of required charges to split from source
Returns
new instance containing exactly qty charges or null item if splitting failed

Definition at line 724 of file item.cpp.

725{
726 if( !count_by_charges() || qty <= 0 || qty >= charges ) {
727 return item();
728 }
729 item res = *this;
730 res.charges = qty;
731 charges -= qty;
732 return res;
733}

References charges, count_by_charges(), and item().

Referenced by iexamine::gaspump(), Character::item_reload_cost(), item_location::impl::item_on_map::obtain(), item_location::impl::item_on_person::obtain(), item_location::impl::item_on_vehicle::obtain(), item_location::impl::item_in_container::obtain(), item_location::impl::item_on_map::obtain_cost(), item_location::impl::item_on_person::obtain_cost(), item_location::impl::item_on_vehicle::obtain_cost(), and bandolier_actor::reload().

◆ spoilage_sort_order()

int item::spoilage_sort_order ( ) const

Get time left to rot, ignoring fridge.

Returns time to rot if item is able to, max int - N otherwise, where N is 3 for food, 2 for medication, 1 for other comestibles, 0 otherwise.

Definition at line 5565 of file item.cpp.

5566{
5567 const item *subject;
5568 constexpr int bottom = std::numeric_limits<int>::max();
5569
5570 if( type->container && !contents.empty() ) {
5571 if( type->container->preserves ) {
5572 return bottom - 3;
5573 }
5574 subject = &contents.front();
5575 } else {
5576 subject = this;
5577 }
5578
5579 if( subject->goes_bad() ) {
5580 return to_turns<int>( subject->get_shelf_life() - subject->rot );
5581 }
5582
5583 if( subject->get_comestible() ) {
5584 if( subject->get_category().get_id() == itemcat_food ) {
5585 return bottom - 3;
5586 } else if( subject->get_category().get_id() == itemcat_drugs ) {
5587 return bottom - 2;
5588 } else {
5589 return bottom - 1;
5590 }
5591 }
5592 return bottom;
5593}
static const item_category_id itemcat_drugs("drugs")
static const item_category_id itemcat_food("food")

References itype::container, contents, item_contents::empty(), item_contents::front(), get_category(), get_comestible(), item_category::get_id(), get_shelf_life(), goes_bad(), itemcat_drugs, itemcat_food, rot, and type.

Referenced by find_auto_consume().

◆ stab_resist()

int item::stab_resist ( bool  to_self = false) const

Definition at line 6100 of file item.cpp.

6101{
6102 // Better than hardcoding it in multiple places
6103 return static_cast<int>( 0.8f * cut_resist( to_self ) );
6104}

References cut_resist().

Referenced by damage_resist().

◆ stacks_with()

bool item::stacks_with ( const item rhs,
bool  check_components = false,
bool  skip_type_check = false 
) const

Definition at line 892 of file item.cpp.

893{
894 if( !skip_type_check && type != rhs.type ) {
895 return false;
896 }
897 if( is_relic() && rhs.is_relic() && !( *relic_data == *rhs.relic_data ) ) {
898 return false;
899 }
900 if( charges != 0 && rhs.charges != 0 && is_money() ) {
901 // Dealing with nonempty cash cards
902 return true;
903 }
904 // This function is also used to test whether items counted by charges should be merged, for that
905 // check the, the charges must be ignored. In all other cases (tools/guns), the charges are important.
906 if( !count_by_charges() && charges != rhs.charges ) {
907 return false;
908 }
909 if( is_favorite != rhs.is_favorite ) {
910 return false;
911 }
912 if( damage_ != rhs.damage_ ) {
913 return false;
914 }
915 if( burnt != rhs.burnt ) {
916 return false;
917 }
918 if( active != rhs.active ) {
919 return false;
920 }
921 if( item_tags != rhs.item_tags ) {
922 return false;
923 }
924 if( faults != rhs.faults ) {
925 return false;
926 }
927 if( techniques != rhs.techniques ) {
928 return false;
929 }
930 if( item_vars != rhs.item_vars ) {
931 return false;
932 }
933 if( goes_bad() && rhs.goes_bad() ) {
934 // Stack items that fall into the same "bucket" of freshness.
935 // Distant buckets are larger than near ones.
936 std::pair<int, clipped_unit> my_clipped_time_to_rot =
938 std::pair<int, clipped_unit> other_clipped_time_to_rot =
939 clipped_time( rhs.get_shelf_life() - rhs.rot );
940 if( my_clipped_time_to_rot != other_clipped_time_to_rot ) {
941 return false;
942 }
943 if( rotten() != rhs.rotten() ) {
944 // just to be safe that rotten and unrotten food is *never* stacked.
945 return false;
946 }
947 }
948 if( ( corpse == nullptr && rhs.corpse != nullptr ) ||
949 ( corpse != nullptr && rhs.corpse == nullptr ) ) {
950 return false;
951 }
952 if( corpse != nullptr && rhs.corpse != nullptr && corpse->id != rhs.corpse->id ) {
953 return false;
954 }
955 if( craft_data_ || rhs.craft_data_ ) {
956 // In-progress crafts are always distinct items. Easier to handle for the player,
957 // and there shouldn't be that many items of this type around anyway.
958 return false;
959 }
960 if( check_components || is_comestible() || is_craft() ) {
961 //Only check if at least one item isn't using the default recipe or is comestible
962 if( !components.empty() || !rhs.components.empty() ) {
964 return false;
965 }
966 }
967 }
969 return false;
970 }
971
972 if( ammo_current() != rhs.ammo_current() ) {
973 return false;
974 }
975
976 return contents.stacks_with( rhs.contents );
977}
std::pair< int, clipped_unit > clipped_time(const time_duration &d)
Returns a value representing the passed in duration truncated to an appropriate unit along with the u...
Definition: calendar.cpp:284
bool stacks_with(const item_contents &rhs) const
std::vector< item_comp > get_uncraft_components() const
Returns a list of components used to craft this item or the default components if it wasn't player-cr...
Definition: item.cpp:10078

References active, ammo_current(), burnt, charges, clipped_time(), components, contents, corpse, count_by_charges(), craft_data_, damage_, faults, get_shelf_life(), get_uncraft_components(), goes_bad(), mtype::id, is_comestible(), is_craft(), is_favorite, is_money(), is_relic(), item_tags, item_vars, item_contents::num_item_stacks(), relic_data, rot, rotten(), item_contents::stacks_with(), techniques, and type.

Referenced by display_stacked_with(), merge_charges(), inventory::restack(), inventory_column::set_stack_favorite(), and npc_trading::transfer_items().

◆ swap_side()

bool item::swap_side ( )

Swap the side on which the item is worn.

Returns false if the item is not sided

Definition at line 833 of file item.cpp.

834{
835 return set_side( opposite_side( get_side() ) );
836}
side opposite_side(side s)
Returns the opposite side.
Definition: bodypart.cpp:30

References get_side(), opposite_side(), and set_side().

Referenced by Character::change_side().

◆ symbol()

const std::string & item::symbol ( ) const

Definition at line 4125 of file item.cpp.

4126{
4127 return type->sym;
4128}
std::string sym
Definition: itype.h:1005

References itype::sym, and type.

Referenced by map::draw_maptile(), map_memory::load_legacy(), mm_elem::operator==(), pickup::pick_up(), mm_submap::serialize(), and debug_menu::wishitem().

◆ tname()

std::string item::tname ( unsigned int  quantity = 1,
bool  with_prefix = true,
unsigned int  truncate = 0 
) const

Return the (translated) item name.

Parameters
quantityused for translation to the proper plural form of the name, e.g. returns "rock" for quantity 1 and "rocks" for quantity > 0.
with_prefixdetermines whether to include more item properties, such as the extent of damage and burning (was created to sort by name without prefix in additional inventory)

Definition at line 4557 of file item.cpp.

4558{
4559 int dirt_level = get_var( "dirt", 0 ) / 2000;
4560 std::string dirt_symbol;
4561 // TODO: MATERIALS put this in json
4562
4563 // these symbols are unicode square characeters of different heights, representing a rough
4564 // estimation of fouling in a gun. This appears instead of "faulty"
4565 // since most guns will have some level of fouling in them, and usually it is not a big deal.
4566 switch( dirt_level ) {
4567 case 0:
4568 dirt_symbol = "";
4569 break;
4570 case 1:
4571 dirt_symbol = "<color_white>\u2581</color>";
4572 break;
4573 case 2:
4574 dirt_symbol = "<color_light_gray>\u2583</color>";
4575 break;
4576 case 3:
4577 dirt_symbol = "<color_light_gray>\u2585</color>";
4578 break;
4579 case 4:
4580 dirt_symbol = "<color_dark_gray>\u2587</color>";
4581 break;
4582 case 5:
4583 dirt_symbol = "<color_brown>\u2588</color>";
4584 break;
4585 default:
4586 dirt_symbol = "";
4587 }
4588 std::string damtext;
4589
4590 // for portions of string that have <color_ etc in them, this aims to truncate the whole string correctly
4591 unsigned int truncate_override = 0;
4592
4593 if( ( damage() != 0 || ( get_option<bool>( "ITEM_HEALTH_BAR" ) && is_armor() ) ) && !is_null() &&
4594 with_prefix ) {
4595 damtext = durability_indicator();
4596 if( get_option<bool>( "ITEM_HEALTH_BAR" ) ) {
4597 // get the utf8 width of the tags
4598 truncate_override = utf8_width( damtext, false ) - utf8_width( damtext, true );
4599 }
4600 }
4601 if( !faults.empty() ) {
4602 bool silent = true;
4603 for( const auto &fault : faults ) {
4604 if( !fault->has_flag( flag_SILENT ) ) {
4605 silent = false;
4606 break;
4607 }
4608 }
4609 if( silent ) {
4610 damtext.insert( 0, dirt_symbol );
4611 } else {
4612 damtext.insert( 0, _( "faulty " ) + dirt_symbol );
4613 }
4614 }
4615
4616 std::string vehtext;
4617 if( is_engine() && engine_displacement() > 0 ) {
4618 vehtext = string_format( pgettext( "vehicle adjective", "%2.1fL " ),
4619 engine_displacement() / 100.0f );
4620
4621 } else if( is_wheel() && type->wheel->diameter > 0 ) {
4622 vehtext = string_format( pgettext( "vehicle adjective", "%d\" " ), type->wheel->diameter );
4623 }
4624
4625 std::string burntext;
4626 if( with_prefix && !made_of( LIQUID ) ) {
4627 if( volume() >= 1_liter && burnt * 125_ml >= volume() ) {
4628 burntext = pgettext( "burnt adjective", "badly burnt " );
4629 } else if( burnt > 0 ) {
4630 burntext = pgettext( "burnt adjective", "burnt " );
4631 }
4632 }
4633
4634 std::string maintext;
4635 if( is_corpse() || typeId() == itype_blood || item_vars.find( "name" ) != item_vars.end() ) {
4636 maintext = type_name( quantity );
4637 } else if( is_gun() || is_tool() || is_magazine() ) {
4638 int amt = 0;
4639 maintext = label( quantity );
4640 for( const item *mod : is_gun() ? gunmods() : toolmods() ) {
4641 if( !type->gun || !type->gun->built_in_mods.count( mod->typeId() ) ) {
4642 amt++;
4643 }
4644 }
4645 if( amt ) {
4646 maintext += string_format( "+%d", amt );
4647 }
4648 } else if( is_armor() && has_clothing_mod() ) {
4649 maintext = label( quantity ) + "+1";
4650 } else if( is_craft() ) {
4651 maintext = string_format( _( "in progress %s" ), craft_data_->making->result_name() );
4652 if( charges > 1 ) {
4653 maintext += string_format( " (%d)", charges );
4654 }
4655 const int percent_progress = item_counter / 100000;
4656 maintext += string_format( " (%d%%)", percent_progress );
4657 } else if( contents.num_item_stacks() == 1 ) {
4658 const item &contents_item = contents.front();
4659 const unsigned contents_count =
4660 ( ( contents_item.made_of( LIQUID ) || contents_item.is_food() ) &&
4661 contents_item.charges > 1 )
4662 ? contents_item.charges
4663 : quantity;
4664 maintext = string_format( pgettext( "item name", "%2$s (%1$s)" ), label( quantity ),
4665 contents_item.tname( contents_count, with_prefix ) );
4666 } else if( !contents.empty() ) {
4667 maintext = string_format( vpgettext( "item name",
4668 //~ %1$s: item name, %2$zd: content size
4669 "%1$s with %2$zd item",
4670 "%1$s with %2$zd items", contents.num_item_stacks() ),
4671 label( quantity ), contents.num_item_stacks() );
4672 } else {
4673 maintext = label( quantity );
4674 }
4675
4676 avatar &you = get_avatar();
4677 std::string tagtext;
4678 if( is_food() ) {
4680 tagtext += _( " (poisonous)" );
4681 } else if( has_flag( flag_HIDDEN_HALLU ) && you.get_skill_level( skill_survival ) >= 5 ) {
4682 tagtext += _( " (hallucinogenic)" );
4683 }
4684 }
4685 if( is_book() ) {
4686 if( !you.has_identified( typeId() ) ) {
4687 tagtext += _( " (unread)" );
4688 }
4689 }
4690 if( has_var( "bionics_scanned_by" ) && has_flag( flag_CBM_SCANNED ) ) {
4691 tagtext += _( " (bionic detected)" );
4692 }
4693 if( has_flag( flag_ETHEREAL_ITEM ) ) {
4694 tagtext += string_format( _( " (%s turns)" ), get_var( "ethereal" ) );
4695 } else if( goes_bad() || is_food() ) {
4696 if( has_own_flag( "DIRTY" ) ) {
4697 tagtext += _( " (dirty)" );
4698 } else if( rotten() ) {
4699 tagtext += _( " (rotten)" );
4700 } else if( is_going_bad() ) {
4701 tagtext += _( " (old)" );
4702 } else if( is_fresh() ) {
4703 tagtext += _( " (fresh)" );
4704 }
4705 if( has_flag( flag_COLD ) ) {
4706 tagtext += _( " (cold)" );
4707 } else if( has_flag( flag_VERY_COLD ) ) {
4708 tagtext += _( " (very cold)" );
4709 }
4710 }
4711
4712 const sizing sizing_level = get_sizing( you, get_encumber( you ) != 0 );
4713
4714 if( sizing_level == sizing::human_sized_small_char ) {
4715 tagtext += _( " (too big)" );
4716 } else if( sizing_level == sizing::big_sized_small_char ) {
4717 tagtext += _( " (huge!)" );
4718 } else if( sizing_level == sizing::human_sized_big_char ||
4719 sizing_level == sizing::small_sized_human_char ) {
4720 tagtext += _( " (too small)" );
4721 } else if( sizing_level == sizing::small_sized_big_char ) {
4722 tagtext += _( " (tiny!)" );
4723 } else if( !has_flag( flag_FIT ) && has_flag( flag_VARSIZE ) ) {
4724 tagtext += _( " (poor fit)" );
4725 }
4726
4727 if( is_filthy() ) {
4728 tagtext += _( " (filthy)" );
4729 }
4731 tagtext += _( " (sterile)" );
4732 }
4733
4734 if( is_tool() && has_flag( flag_USE_UPS ) && !has_flag( flag_NAT_UPS ) ) {
4735 tagtext += _( " (UPS)" );
4736 }
4737 if( is_tool() && has_flag( flag_HEATS_FOOD ) ) {
4738 tagtext += _( " (heats)" );
4739 }
4740
4741 if( has_var( "NANOFAB_ITEM_ID" ) ) {
4742 tagtext += string_format( " (%s)", nname( itype_id( get_var( "NANOFAB_ITEM_ID" ) ) ) );
4743 }
4744
4745 if( has_flag( flag_RADIO_MOD ) ) {
4746 tagtext += _( " (radio:" );
4747 if( has_flag( flag_RADIOSIGNAL_1 ) ) {
4748 tagtext += pgettext( "The radio mod is associated with the [R]ed button.", "R)" );
4749 } else if( has_flag( flag_RADIOSIGNAL_2 ) ) {
4750 tagtext += pgettext( "The radio mod is associated with the [B]lue button.", "B)" );
4751 } else if( has_flag( flag_RADIOSIGNAL_3 ) ) {
4752 tagtext += pgettext( "The radio mod is associated with the [G]reen button.", "G)" );
4753 } else {
4754 debugmsg( "Why is the radio neither red, blue, nor green?" );
4755 tagtext += "?)";
4756 }
4757 }
4758
4759 if( has_flag( flag_WET ) ) {
4760 tagtext += _( " (wet)" );
4761 }
4762 if( already_used_by_player( you ) ) {
4763 tagtext += _( " (used)" );
4764 }
4766 tagtext += _( " (lit)" );
4767 } else if( has_flag( flag_IS_UPS ) && get_var( "cable" ) == "plugged_in" ) {
4768 tagtext += _( " (plugged in)" );
4769 } else if( active && !is_food() && !is_corpse() &&
4770 !string_ends_with( typeId().str(), "_on" ) ) {
4771 // Usually the items whose ids end in "_on" have the "active" or "on" string already contained
4772 // in their name, also food is active while it rots.
4773 tagtext += _( " (active)" );
4774 }
4775
4776 if( is_favorite ) {
4777 tagtext += _( " *" ); // Display asterisk for favorite items
4778 }
4779
4780 std::string modtext;
4782 modtext += _( "sawn-off " );
4783 }
4785 modtext += _( "pistol " );
4786 }
4787 if( has_flag( flag_DIAMOND ) ) {
4788 modtext += std::string( pgettext( "Adjective, as in diamond katana", "diamond" ) ) + " ";
4789 }
4790
4791 //~ This is a string to construct the item name as it is displayed. This format string has been added for maximum flexibility. The strings are: %1$s: Damage text (e.g. "bruised"). %2$s: burn adjectives (e.g. "burnt"). %3$s: tool modifier text (e.g. "atomic"). %4$s: vehicle part text (e.g. "3.8-Liter"). $5$s: main item text (e.g. "apple"). %6s: tags (e.g. "(wet) (poor fit)").
4792 std::string ret = string_format( _( "%1$s%2$s%3$s%4$s%5$s%6$s" ), damtext, burntext, modtext,
4793 vehtext, maintext, tagtext );
4794
4795 if( truncate != 0 ) {
4796 ret = utf8_truncate( ret, truncate + truncate_override );
4797 }
4798
4799 if( item_vars.find( "item_note" ) != item_vars.end() ) {
4800 //~ %s is an item name. This style is used to denote items with notes.
4801 return string_format( _( "*%s*" ), ret );
4802 } else {
4803 return ret;
4804 }
4805}
int utf8_width(const char *s, const bool ignore_tags)
std::string utf8_truncate(const std::string &s, size_t length)
bool has_flag(const std::string &flag) const
Definition: fault.h:61
bool is_wheel() const
Definition: item.cpp:6763
bool is_going_bad() const
an item is about to become rotten when shelf life has nearly elapsed
Definition: item.h:845
std::string durability_indicator(bool include_intact=false) const
Provides a prefix for the durability state of the item.
Definition: item.cpp:6324
std::string label(unsigned int quantity=0) const
Returns label from "item_label" itemvar and quantity.
Definition: item.cpp:9973
bool is_fresh() const
an item is fresh if it is capable of rotting but still has a long shelf life remaining
Definition: item.h:840
bool has_clothing_mod() const
Definition: item.cpp:10154
int engine_displacement() const
for combustion engines the displacement (cc)
Definition: item.cpp:4120
bool already_used_by_player(const player &p) const
Check whether the item has been marked (by calling mark_as_used_by_player) as used by this specific p...
Definition: item.cpp:8861
static const itype_id itype_blood("blood")
static const std::string flag_SILENT("SILENT")
static const std::string flag_HEATS_FOOD("HEATS_FOOD")
static const itype_id itype_stock_small("stock_small")
static const std::string flag_NAT_UPS("NAT_UPS")
static const itype_id itype_barrel_small("barrel_small")
static const std::string flag_CBM_SCANNED("CBM_SCANNED")
bool string_ends_with(const std::string &s1, const std::string &s2)
Returns true if s1 ends with s2.
Struct used for storing labels (easier to json opposed to a std::map<point, std::string>)
Definition: vehicle.h:579
const char * vpgettext(const char *const context, const char *const msgid, const char *const msgid_plural, const size_t n)
@ silent
Definition: weather_type.h:56

References _, active, already_used_by_player(), big_sized_small_char, burnt, charges, contents, craft_data_, damage(), debugmsg, durability_indicator(), item_contents::empty(), engine_displacement(), fault_bionic_nonsterile, faults, flag_CBM_SCANNED(), flag_COLD(), flag_DIAMOND(), flag_ETHEREAL_ITEM(), flag_FIT(), flag_HEATS_FOOD(), flag_HIDDEN_HALLU(), flag_HIDDEN_POISON(), flag_IS_UPS(), flag_LITCIG(), flag_NAT_UPS(), flag_RADIO_MOD(), flag_RADIOSIGNAL_1(), flag_RADIOSIGNAL_2(), flag_RADIOSIGNAL_3(), flag_SILENT(), flag_USE_UPS(), flag_VARSIZE(), flag_VERY_COLD(), flag_WATER_EXTINGUISH(), flag_WET(), item_contents::front(), get_avatar(), get_encumber(), get_sizing(), Character::get_skill_level(), get_var(), goes_bad(), itype::gun, gunmod_find(), gunmods(), has_clothing_mod(), has_fault(), fault::has_flag(), has_flag(), avatar::has_identified(), has_own_flag(), has_var(), human_sized_big_char, human_sized_small_char, is_armor(), is_bionic(), is_book(), is_corpse(), is_craft(), is_engine(), is_favorite, is_filthy(), is_food(), is_fresh(), is_going_bad(), is_gun(), is_magazine(), is_null(), is_tool(), is_wheel(), item_counter, item_vars, itype_barrel_small, itype_blood, itype_id, itype_stock_small, label(), LIQUID, made_of(), nname(), item_contents::num_item_stacks(), pgettext(), cata::hash64_detail::ret, rotten(), silent, skill_survival, small_sized_big_char, small_sized_human_char, string_ends_with(), string_format(), tname(), toolmods(), type, type_name(), typeId(), utf8_truncate(), utf8_width(), volume(), vpgettext(), and itype::wheel.

Referenced by Character::absorb_hit(), advanced_inventory::action_examine(), monexamine::add_armor(), game::add_artifact_dreams(), add_disassemblables(), MapgenRemovePartHandler::add_item_or_charges(), advanced_inventory_pane::add_items_from_area(), auto_pickup::player_settings::add_rule(), add_salvagables(), npc::alt_attack(), ammo_consume(), apply_lock_picking_tool(), apply_prying_tool(), Character::armor_absorb(), iuse::artifact(), inventory::assign_empty_invlet(), mattack::bio_op_disarm(), talk_function::bionic_remove(), Character::block_hit(), Character::block_ranged_hit(), iuse::blood_draw(), iuse::burrow(), activity_handlers::butcher_finish(), camp_car_description(), use_function::can_call(), npc::can_read(), repair_item_actor::can_repair_target(), Character::can_unwield(), Character::can_use(), Character::can_wear(), Character::can_wield(), iuse::capture_monster_act(), iuse::capture_monster_veh(), Character::change_side(), charges_per_volume(), iuse::chew(), iuse::coin_flip(), colorized_item_name(), game_menus::inv::compare(), crafting::complete_disassemble(), npc::confident_gun_mode_range(), Character::consume(), Character::consume_item(), iuse::contacts(), game_menus::inv::container_for(), iuse::craft(), auto_pickup::rule_list::create_rule(), iuse::crowbar(), salvage_actor::cut_up(), damage_item(), deactivate(), item_location::impl::item_in_container::describe(), iexamine::dimensional_portal(), iuse::directional_hologram(), display_money(), display_name(), iuse::dive_tank(), npc::do_reload(), draw_bionics_titlebar(), npc::drop_items(), drop_on_map(), drop_or_embed_projectile(), avatar_action::eat(), Character::eat(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), npc::execute_action(), Character::extended_description(), iuse::eyedrops(), Character::feed_furnace_with(), fetch_activity(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), npc::find_item(), heal_actor::finish_using(), ranged::fire_gun(), avatar_action::fire_wielded_weapon(), iuse::firecracker_act(), iexamine::fireplace(), iuse::fishing_rod(), iuse::flumed(), iuse::flusleep(), character_funcs::fmt_wielded_weapon(), Character::fuel_bionic_with(), iexamine::fvat_empty(), iexamine::fvat_full(), activity_handlers::game_do_turn(), iuse::gasmask(), generic_multi_activity_do(), avatar::get_book_reader(), get_continue_reqs(), get_encumber_when_containing(), get_making(), get_next_failure_point(), get_owner_name(), get_property_int64_t(), get_remaining_capacity_for_liquid(), vehicle::get_targeting_npc(), talk_function::give_equipment(), monexamine::give_items_to(), iuse::granade_act(), iuse::gun_repair(), avatar_funcs::gunmod_add(), activity_handlers::gunmod_add_finish(), avatar_funcs::gunmod_remove(), ranged::gunmode_checks_common(), ranged::gunmode_checks_weapon(), iuse::hand_crank(), repair_item_actor::handle_components(), handle_craft_failure(), ranged::handle_gun_damage(), liquid_handler::handle_liquid(), Character::handle_melee_wear(), handle_problematic_pickup(), Character::has_enough_charges(), auto_pickup::player_settings::has_rule(), npc::heal_self(), Character::i_add_to_container(), Character::i_rem(), ideal_ranged_dps(), iuse_transform::info(), info(), Character::invoke_item(), avatar::invoke_item(), advanced_inventory_pane::is_filtered(), Character::item_reload_cost(), npc::item_whitelisted(), iuse::jackhammer(), iexamine::keg(), game::list_items(), aim_activity_actor::load_RAS_weapon(), iuse::magic_8_ball(), marloss_common(), iuse::marloss_seed(), character_martial_arts::martialart_use_message(), iuse::meditate(), iuse::melatonin_tablet(), Character::melee_special_effects(), activity_handlers::mend_item_finish(), iuse::mind_splicer(), mod_charges(), mod_last_rot_check(), Character::modify_morale(), iuse::molotov_lit(), npc::mug_player(), iuse::multicooker(), Character::mutation_effect(), npc_throw(), on_wield(), iuse::oxygen_bottle(), iuse::pack_item(), target_ui::panel_gun_info(), parse_tags(), petfood(), pick_one_up(), iuse::pickaxe(), iuse::play_game(), avatar_action::plthrow(), iuse::portable_game(), Character::pour_into(), iexamine::pour_into_keg(), npc::pretend_fire(), game::print_items_info(), game::process_artifact(), process_blackpowder_fouling(), process_extinguish(), map::process_fields_in_submap(), process_internal(), process_litcig(), process_tool(), ranged::prompt_select_default_ammo_for(), mattack::pull_metal_weapon(), put_into_vehicle(), item_reload_option::qty(), iuse::radio_mod(), iuse::radiocar(), character_funcs::rate_sleep_spot(), player::reduce_charges(), avatar_action::reload(), bandolier_actor::reload(), reload(), activity_handlers::reload_finish(), remove_radio_mod(), auto_pickup::player_settings::remove_rule(), repair_item_actor::repair(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), map::rotten_item_spawn(), iuse::rpgdie(), examine_item_menu::run(), iuse::seed(), character_funcs::select_ammo(), talk_effect_fun_t::set_bulk_trade_accept(), talk_effect_fun_t::set_consume_item(), set_item_inventory(), set_item_map(), set_item_map_or_vehicle(), set_mtype(), set_next_failure_point(), talk_effect_fun_t::set_u_buy_item(), gun_actor::shoot(), trading_window::show_item_data(), sleep(), smash(), iuse::smoking(), iuse::solarpack(), holster_actor::store(), npc::stow_item(), Character::suffer_from_bad_bionics(), monexamine::take_items_from(), Character::takeoff(), iuse::talking_doll(), tname(), iuse::toggle_heats_food(), tool_info(), iuse::towel_common(), iexamine::tree_maple_tapped(), try_consume(), avatar_funcs::try_disarm_npc(), try_reject_mutagen(), avatar_funcs::try_steal_from_npc(), salvage_actor::try_to_cut_up(), target_ui::uitext_title(), iuse::unfold_generic(), avatar_funcs::unload_item(), iuse::unpack_item(), Character::unwield(), inventory_entry::update_cache(), iuse_transform::use(), countdown_actor::use(), explosion_iuse::use(), unfold_vehicle_iuse::use(), set_transform_iuse::use(), change_scent_iuse::use(), deploy_furn_actor::use(), reveal_map_actor::use(), firestarter_actor::use(), inscribe_actor::use(), holster_actor::use(), ammobelt_actor::use(), heal_actor::use(), place_trap_actor::use(), deploy_tent_actor::use(), saw_barrel_actor::use(), saw_stock_actor::use(), unpack_actor::use(), cast_spell_actor::use(), heal_actor::use_healing_item(), avatar_funcs::use_item(), npc::use_painkiller(), iuse::vibe(), activity_handlers::vibe_do_turn(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), avatar_action::wield(), Character::will_eat(), wind_resist(), debug_menu::wishitem(), memorial_logger::write(), and iuse::xanax().

◆ tool_info()

void item::tool_info ( std::vector< iteminfo > &  info,
const iteminfo_query parts,
int  batch,
bool  debug 
) const

Definition at line 3084 of file item.cpp.

3086{
3087 if( !is_tool() ) {
3088 return;
3089 }
3090
3092 if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CHARGES ) ) {
3093 info.emplace_back( "TOOL", string_format( _( "<bold>Charges</bold>: %d" ),
3094 ammo_remaining() ) );
3095 }
3096
3097 if( !magazine_integral() ) {
3099 info.emplace_back( "TOOL", _( "Magazine: " ),
3100 string_format( "<stat>%s</stat>", magazine_current()->tname() ) );
3101 }
3102
3104 const std::set<itype_id> compat = magazine_compatible();
3105 info.emplace_back( "TOOL", _( "Compatible magazines: " ),
3106 enumerate_as_string( compat.begin(), compat.end(), []( const itype_id & id ) {
3107 return item::nname( id );
3108 } ) );
3109 }
3110 } else if( ammo_capacity() != 0 && parts->test( iteminfo_parts::TOOL_CAPACITY ) ) {
3111 std::string tmp;
3112 bool bionic_tool = has_flag( flag_USES_BIONIC_POWER );
3113 if( !ammo_types().empty() ) {
3114 //~ "%s" is ammunition type. This types can't be plural.
3115 tmp = vgettext( "Maximum <num> charge of %s.", "Maximum <num> charges of %s.",
3116 ammo_capacity() );
3117 tmp = string_format( tmp, enumerate_as_string( ammo_types().begin(),
3118 ammo_types().end(), []( const ammotype & at ) {
3119 return at->name();
3121
3122 // No need to display max charges, since charges are always equal to bionic power
3123 } else if( !bionic_tool ) {
3124 tmp = vgettext( "Maximum <num> charge.", "Maximum <num> charges.", ammo_capacity() );
3125 }
3126 if( !bionic_tool ) {
3127 info.emplace_back( "TOOL", "", tmp, iteminfo::no_flags, ammo_capacity() );
3128 }
3129 }
3130}

References _, ammo_capacity(), ammo_remaining(), ammo_types(), enumerate_as_string(), flag_USES_BIONIC_POWER(), has_flag(), info(), insert_separation_line(), is_tool(), magazine_compatible(), magazine_current(), magazine_integral(), ammunition_type::name(), iteminfo::no_flags, none, string_format(), iteminfo_query::test(), tname(), TOOL_CAPACITY, TOOL_CHARGES, TOOL_MAGAZINE_COMPATIBLE, TOOL_MAGAZINE_CURRENT, and vgettext().

Referenced by info().

◆ toolmods() [1/2]

std::vector< item * > item::toolmods ( )

Returns all toolmods currently attached to this item (always empty if item not a tool)

Definition at line 5457 of file item.cpp.

5458{
5459 std::vector<item *> res;
5460 if( is_tool() ) {
5461 for( item *e : contents.all_items_top() ) {
5462 if( e->is_toolmod() ) {
5463 res.push_back( e );
5464 }
5465 }
5466 }
5467 return res;
5468}

References item_contents::all_items_top(), contents, and is_tool().

Referenced by ammo_capacity(), ammo_data(), ammo_types(), contents_info(), has_flag(), magazine_compatible(), magazine_default(), magazine_integral(), iuse::remove_all_mods(), tname(), and iuse::toolmod_attach().

◆ toolmods() [2/2]

std::vector< const item * > item::toolmods ( ) const

Definition at line 5470 of file item.cpp.

5471{
5472 std::vector<const item *> res;
5473 if( is_tool() ) {
5474 for( const item *e : contents.all_items_top() ) {
5475 if( e->is_toolmod() ) {
5476 res.push_back( e );
5477 }
5478 }
5479 }
5480 return res;
5481}

References item_contents::all_items_top(), contents, and is_tool().

◆ type_name()

std::string item::type_name ( unsigned int  quantity = 1) const

Name of the item type (not the item), with proper plural.

This is only special when the item itself has a special name ("name" entry in item_tags) or is a named corpse. It's effectively the same as calling nname with the item type id. Use this when the actual item is not meant, for example "The shovel" instead of "Your shovel". Or "The jacket is too small", when it applies to all jackets, not just the one the character tried to wear).

Definition at line 9872 of file item.cpp.

9873{
9874 const auto iter = item_vars.find( "name" );
9875 std::string ret_name;
9876 if( typeId() == itype_blood ) {
9877 if( corpse == nullptr || corpse->id.is_null() ) {
9878 return vpgettext( "item name", "human blood", "human blood", quantity );
9879 } else {
9880 return string_format( vpgettext( "item name", "%s blood",
9881 "%s blood", quantity ),
9882 corpse->nname() );
9883 }
9884 } else if( iter != item_vars.end() ) {
9885 return iter->second;
9886 } else {
9887 ret_name = type->nname( quantity );
9888 }
9889
9890 // Apply conditional names, in order.
9891 for( const conditional_name &cname : type->conditional_names ) {
9892 // Lambda for recursively searching for a item ID among all components.
9893 std::function<bool ( std::list<item> )> component_id_contains =
9894 [&]( std::list<item> components ) {
9895 for( const item &component : components ) {
9896 if( component.typeId().str().find( cname.condition ) != std::string::npos ||
9897 component_id_contains( component.components ) ) {
9898 return true;
9899 }
9900 }
9901 return false;
9902 };
9903 switch( cname.type ) {
9905 if( has_flag( cname.condition ) ) {
9906 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9907 }
9908 break;
9910 if( component_id_contains( components ) ) {
9911 ret_name = string_format( cname.name.translated( quantity ), ret_name );
9912 }
9913 break;
9915 break;
9916 }
9917 }
9918
9919 // Identify who this corpse belonged to, if applicable.
9920 if( corpse != nullptr && has_flag( flag_CORPSE ) ) {
9921 if( corpse_name.empty() ) {
9922 //~ %1$s: name of corpse with modifiers; %2$s: species name
9923 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of a %2$s" ),
9924 ret_name, corpse->nname() );
9925 } else {
9926 //~ %1$s: name of corpse with modifiers; %2$s: proper name; %3$s: species name
9927 ret_name = string_format( pgettext( "corpse ownership qualifier", "%1$s of %2$s, %3$s" ),
9928 ret_name, corpse_name, corpse->nname() );
9929 }
9930 }
9931
9932 return ret_name;
9933}
@ COMPONENT_ID
Definition: itype.h:809
@ FLAG
Definition: itype.h:808
@ num_condition_types
Definition: itype.h:810
std::string condition
Definition: itype.h:823
translation name
Definition: itype.h:826
condition_type type
Definition: itype.h:821
std::vector< conditional_name > conditional_names
Definition: itype.h:918

References COMPONENT_ID, components, conditional_name::condition, itype::conditional_names, corpse, corpse_name, FLAG, flag_CORPSE(), has_flag(), mtype::id, string_id< T >::is_null(), item_vars, itype_blood, conditional_name::name, itype::nname(), mtype::nname(), num_condition_types, pgettext(), string_format(), translation::translated(), type, conditional_name::type, typeId(), and vpgettext().

Referenced by advanced_inventory::action_examine(), Character::can_wear(), game_menus::inv::compare(), avatar::do_read(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), npc::finish_read(), character_funcs::fmt_wielded_weapon(), trading_window::get_var_trade(), Character::is_snuggling(), inscribe_actor::item_inscription(), label(), game::list_items(), Character::pour_into(), avatar::read(), bandolier_actor::reload(), game_menus::inv::repair(), examine_item_menu::run(), trading_window::show_item_data(), skim_book_msg(), Character::suffer_from_schizophrenia(), tname(), consume_drug_iuse::use(), place_monster_iuse::use(), and bandolier_actor::use().

◆ typeId()

const itype_id & item::typeId ( ) const

return the unique identifier of the items underlying type

Definition at line 8366 of file item.cpp.

8367{
8368 return type ? type->get_id() : itype_id::NULL_ID();
8369}

References itype::get_id(), string_id< itype >::NULL_ID(), and type.

Referenced by computer_session::action_blood_anal(), computer_session::action_data_anal(), add_disassemblables(), inventory::add_item_by_items_type_cache(), map::add_item_or_charges(), add_rain_to_container(), item_pricing::adjust_values(), vehicle_part::ammo_current(), ammo_set(), amount_of_internal(), armor_fit_info(), inventory::assign_empty_invlet(), iexamine::autodoc(), basic_info(), iuse::bell(), mattack::bio_op_takedown(), book_info(), Character::can_fuel_bionic_with(), vehicle_part::can_reload(), bandolier_actor::can_store(), Character::can_use_heal_item(), Character::can_wear(), Character::can_wield(), color_in_inventory(), combat_info(), crafting::complete_disassemble(), Character::compute_nutrient_range(), prepared_item_consumption::consume(), vehicle_part::consume_energy(), consumption_event::consumption_event(), mattack::copbot(), map::create_burnproducts(), iuse::directional_antenna(), disassembly_info(), Character::dismount(), iuse::dive_tank(), avatar::do_read(), npc::do_reload(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), editmap::draw_main_ui_overlay(), iuse::ecig(), iuse::ehandcuffs(), explosion_handler::emp_blast(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), farm_valid_seed(), fetch_activity(), talk_function::field_harvest(), talk_function::field_plant(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), character_funcs::find_ammo_helper(), iexamine::fireplace(), food_info(), Character::fuel_bionic_with(), Character::fun_for(), iexamine::fvat_empty(), iuse::geiger(), json_talk_topic::gen_responses(), generic_multi_activity_do(), Character::get_acquirable_energy(), inventory::get_binned_items(), Character::get_bionic_fueled_with(), character_funcs::get_book_fun_for(), read_inventory_preset::get_denial(), bionic_install_preset::get_failure_chance(), Character::get_overlay_ids(), disassemble_inventory_preset::get_recipe(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), get_uncraft_components(), give_item_to(), mattack::grab(), iuse::granade_act(), Character::has_active_item(), inventory::has_enough_painkiller(), Character::i_add(), Character::i_add_to_container(), monster::init_from_item(), init_memory_card_with_random_stuff(), io(), advanced_inv_area::is_container_valid(), character_funcs::is_fun_to_read(), is_funnel_container(), is_gunmod_compatible(), read_inventory_preset::is_known(), is_null(), is_reloadable_helper(), ma_requirements::is_valid_character(), item(), Character::item_handling_cost(), iexamine::keg(), ma_style_callback::key(), aim_activity_actor::load_RAS_weapon(), iuse::lumber(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), to_cbc_migration::migration_required(), iuse::mind_splicer(), Item_modifier::modify(), advanced_inventory::move_content(), iuse::mp3(), iuse::mp3_on(), item_stack::only_item(), iuse::pack_cbm(), iuse::pack_item(), iexamine::pedestal_temple(), iexamine::pedestal_wyrm(), peek_related_recipe(), pick_usb(), avatar_action::plthrow(), iexamine::pour_into_keg(), process_extinguish(), process_litcig(), examine_item_menu::rate_action_disassemble(), examine_item_menu::rate_action_read(), avatar::read(), game_menus::inv::reassign_letter(), reload(), activity_handlers::reload_finish(), repair_item_actor::repair_recipe_difficulty(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), advanced_inv_area::set_container(), talk_effect_fun_t::set_remove_item_with(), player_morale::set_worn(), iuse::smoking(), iuse::solarpack(), iuse::solarpack_off(), Character::suffer_from_bad_bionics(), Character::suffer_from_radiation(), iuse::talking_doll(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), disassemble_activity_actor::try_start_single(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), type_name(), iuse::unpack_item(), inventory::update_cache_with_item(), inventory::update_invlet(), unfold_vehicle_iuse::use(), musical_instrument_actor::use(), unpack_actor::use(), use_amount_internal(), map::use_amount_square(), Character::use_charges(), map::use_charges(), avatar_funcs::use_item(), vehicle::use_washing_machine(), npc::value(), vehicle_part::vehicle_part(), volume(), iuse::water_purifier(), martialart::weapon_valid(), Character::wear_item(), iuse::weather_tool(), avatar::wield(), npc::wield_better_weapon(), and wind_resist().

◆ units_remaining()

int item::units_remaining ( const Character ch,
int  limit = INT_MAX 
) const

How many units (ammo or charges) are remaining?

Parameters
chcharacter responsible for invoking the item
limitstop searching after this many units found
Note
also checks availability of UPS charges if applicable

Definition at line 8000 of file item.cpp.

8001{
8002 if( count_by_charges() ) {
8003 return std::min( static_cast<int>( charges ), limit );
8004 }
8005
8006 int res = ammo_remaining();
8007 if( res < limit && is_power_armor() ) {
8009 res += std::max( ch.charges_of( itype_UPS, limit - res ), ch.charges_of( itype_bio_armor,
8010 limit - res ) );
8011 } else if( character_funcs::can_interface_armor( ch ) ) {
8012 res += ch.charges_of( itype_bio_armor, limit - res );
8013 } else {
8014 res += ch.charges_of( itype_UPS, limit - res );
8015 }
8016 } else if( res < limit && has_flag( flag_USE_UPS ) ) {
8017 res += ch.charges_of( itype_UPS, limit - res );
8018 }
8019
8020 return std::min( static_cast<int>( res ), limit );
8021}
int charges_of(const itype_id &what, int limit=INT_MAX, const std::function< bool(const item &)> &filter=return_true< item >, std::function< void(int)> visitor=nullptr) const
Count maximum available charges from this instance and any contained items.
Definition: visitable.cpp:946

References ammo_remaining(), character_funcs::can_interface_armor(), charges, visitable< T >::charges_of(), count_by_charges(), flag_USE_UPS(), has_flag(), is_power_armor(), itype_bio_armor, and itype_UPS.

Referenced by iuse::portable_game(), units_sufficient(), iuse_transform::use(), and set_transform_iuse::use().

◆ units_sufficient()

bool item::units_sufficient ( const Character ch,
int  qty = -1 
) const

Check if item has sufficient units (ammo or charges) remaining.

Parameters
chCharacter to check (used if ammo is UPS charges)
qtyunits required, if unspecified use item default

Definition at line 8023 of file item.cpp.

8024{
8025 if( qty < 0 ) {
8026 qty = count_by_charges() ? 1 : ammo_required();
8027 }
8028
8029 return units_remaining( ch, qty ) == qty;
8030}
int units_remaining(const Character &ch, int limit=INT_MAX) const
How many units (ammo or charges) are remaining?
Definition: item.cpp:8000

References ammo_required(), count_by_charges(), and units_remaining().

Referenced by cauterize_actor::can_use(), iuse::gun_repair(), iuse::mp3(), iuse::multicooker(), iuse::noise_emitter_off(), iuse::radglove(), iuse::radio_off(), iuse::radiocontrol(), iuse::remoteveh(), activity_handlers::repair_item_finish(), iuse::robotcontrol(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), iuse::talking_doll(), iuse::tazer(), toolweapon_off(), toolweapon_on(), iuse::vibe(), and iuse::water_purifier().

◆ unset_flag()

item & item::unset_flag ( const std::string &  flag)

◆ unset_flags()

void item::unset_flags ( )

Removes all item specific flags.

Definition at line 5296 of file item.cpp.

5297{
5298 item_tags.clear();
5299}

References item_tags.

Referenced by iuse::camera(), einkpc_download_memory_card(), and iuse::einktabletpc().

◆ update_clothing_mod_val()

void item::update_clothing_mod_val ( )

Definition at line 10171 of file item.cpp.

10172{
10175 type );
10176 float tmp = 0.0;
10177 for( const clothing_mod &cm : clothing_mods::get_all_with( type ) ) {
10178 if( has_own_flag( cm.flag ) ) {
10179 tmp += cm.get_mod_val( type, *this );
10180 }
10181 }
10182 set_var( key, tmp );
10183 }
10184}
clothing_mod_type
Definition: clothing_mod.h:16
const std::vector< clothing_mod > & get_all_with(clothing_mod_type type)
constexpr std::array< clothing_mod_type, 9 > all_clothing_mod_types
Definition: clothing_mod.h:63

References clothing_mods::all_clothing_mod_types, CLOTHING_MOD_VAR_PREFIX(), clothing_mods::get_all_with(), has_own_flag(), set_var(), clothing_mods::string_from_clothing_mod_type(), and type.

Referenced by sew_advanced_actor::use().

◆ use_amount()

bool item::use_amount ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consume a specific amount of items of a specific type.

This includes this item, and any of its contents (recursively).

See also
item::use_charges - this is similar for items, not charges.
Parameters
itType of consumable item.
quantityHow much to consumed.
usedOn success all consumed items will be stored here.
filterMust return true for use to occur.

Definition at line 8504 of file item.cpp.

8506{
8507 // Remember quantity so that we can unseal self
8508 int old_quantity = quantity;
8509 std::vector<item *> removed_items;
8510 // First, check contents
8512 [&]( item * a ) {
8513 // visit_items checks the item itself first. we want to do its contents first.
8514 if( a == this ) {
8515 return VisitResponse::NEXT;
8516 }
8517 if( a->use_amount_internal( it, quantity, used, filter ) ) {
8518 removed_items.emplace_back( a );
8519 return VisitResponse::SKIP;
8520 }
8521 return VisitResponse::NEXT;
8522 } );
8523
8524 for( item *remove : removed_items ) {
8525 remove_item( *remove );
8526 }
8527
8528 if( quantity != old_quantity ) {
8530 }
8531 return use_amount_internal( it, quantity, used, filter );
8532}
bool use_amount_internal(const itype_id &it, int &quantity, std::list< item > &used, const std::function< bool(const item &)> &filter=return_true< item >)
Definition: item.cpp:8534
constexpr double a
Definition: magic.cpp:1030

References a, NEXT, on_contents_changed(), visitable< item >::remove_item(), use_amount_internal(), and visitable< item >::visit_items().

◆ use_amount_internal()

bool item::use_amount_internal ( const itype_id it,
int &  quantity,
std::list< item > &  used,
const std::function< bool(const item &)> &  filter = return_true<item> 
)
private

Definition at line 8534 of file item.cpp.

8536{
8537 if( typeId() == it && quantity > 0 && filter( *this ) ) {
8538 used.push_back( *this );
8539 quantity--;
8540 return true;
8541 } else {
8542 return false;
8543 }
8544}

References typeId().

Referenced by use_amount().

◆ use_charges()

bool item::use_charges ( const itype_id what,
int &  qty,
std::list< item > &  used,
const tripoint pos,
const std::function< bool(const item &)> &  filter = return_true<item> 
)

Consumes specified charges (or fewer) from this and any contained items.

Parameters
whatspecific type of charge required, e.g. 'battery'
qtymaximum charges to consume. On return set to number of charges not found (or zero)
usedfilled with duplicates of each item that provided consumed charges
posposition at which the charges are being consumed
filterMust return true for use to occur.
Returns
true if this item should be deleted (count-by-charges items with no remaining charges)

Definition at line 8624 of file item.cpp.

8626{
8627 std::vector<item *> del;
8628
8629 visit_items( [&what, &qty, &used, &pos, &del, &filter]( item * e, item * parent ) {
8630 if( qty == 0 ) {
8631 // found sufficient charges
8632 return VisitResponse::ABORT;
8633 }
8634
8635 if( !filter( *e ) ) {
8636 return VisitResponse::NEXT;
8637 }
8638
8639 if( e->is_tool() ) {
8640 if( e->typeId() == what ) {
8641 int n = std::min( e->ammo_remaining(), qty );
8642 qty -= n;
8643
8644 used.push_back( item( *e ).ammo_set( e->ammo_current(), n ) );
8645 e->ammo_consume( n, pos );
8646 }
8647 return VisitResponse::SKIP;
8648
8649 } else if( e->count_by_charges() ) {
8650 if( e->typeId() == what ) {
8651
8652 // if can supply excess charges split required off leaving remainder in-situ
8653 item obj = e->split( qty );
8654 if( parent ) {
8655 parent->on_contents_changed();
8656 }
8657 if( !obj.is_null() ) {
8658 used.push_back( obj );
8659 qty = 0;
8660 return VisitResponse::ABORT;
8661 }
8662
8663 qty -= e->charges;
8664 used.push_back( *e );
8665 del.push_back( e );
8666 }
8667 // items counted by charges are not themselves expected to be containers
8668 return VisitResponse::SKIP;
8669 }
8670
8671 // recurse through any nested containers
8672 return VisitResponse::NEXT;
8673 } );
8674
8675 bool destroy = false;
8676 for( item *e : del ) {
8677 if( e == this ) {
8678 destroy = true; // cannot remove ourselves...
8679 } else {
8680 remove_item( *e );
8681 }
8682 }
8683
8684 return destroy;
8685}

References ABORT, count_by_charges(), is_tool(), NEXT, SKIP, and visitable< item >::visit_items().

Referenced by Character::use_charges(), and use_charges_from_furn().

◆ validate_ownership()

void item::validate_ownership ( ) const

Definition at line 1294 of file item.cpp.

1295{
1296 if( !old_owner.is_null() && !g->faction_manager_ptr->get( old_owner, false ) ) {
1298 }
1299 if( !owner.is_null() && !g->faction_manager_ptr->get( owner, false ) ) {
1300 remove_owner();
1301 }
1302}
void remove_old_owner() const
Definition: item.h:2026
void remove_owner() const
Definition: item.h:2033

References g, string_id< T >::is_null(), old_owner, owner, remove_old_owner(), and remove_owner().

Referenced by get_old_owner(), and get_owner().

◆ volume()

units::volume item::volume ( bool  integral = false) const

Total volume of an item accounting for all contained/integrated items NOTE: Result is rounded up to next nearest milliliter when working with stackable (count_by_charges) items that have fractional volume per charge.

If trying to determine how many of an item can fit in a given space, charges_per_volume should be used instead.

Parameters
integralif true return effective volume if this item was integrated into another

Definition at line 5112 of file item.cpp.

5113{
5114 if( is_null() ) {
5115 return 0_ml;
5116 }
5117
5118 if( is_corpse() ) {
5119 return corpse_volume( corpse );
5120 }
5121
5122 if( is_craft() ) {
5123 units::volume ret = 0_ml;
5124 for( const item &it : components ) {
5125 ret += it.volume();
5126 }
5127 return ret;
5128 }
5129
5130 const int local_volume = get_var( "volume", -1 );
5132 if( local_volume >= 0 ) {
5133 ret = local_volume * units::legacy_volume_factor;
5134 } else if( integral ) {
5136 } else {
5137 ret = type->volume;
5138 }
5139
5140 if( count_by_charges() || made_of( LIQUID ) ) {
5142 ( charges );
5143 if( type->stack_size <= 0 ) {
5144 debugmsg( "Item type %s has invalid stack_size %d", typeId().str(), type->stack_size );
5145 ret = num;
5146 } else {
5147 ret = num / type->stack_size;
5148 if( num % type->stack_size != 0_ml ) {
5149 ret += 1_ml;
5150 }
5151 }
5152 }
5153
5154 // Non-rigid items add the volume of the content
5155 if( !type->rigid ) {
5157 }
5158
5159 // Some magazines sit (partly) flush with the item so add less extra volume
5160 if( magazine_current() != nullptr ) {
5161 ret += std::max( magazine_current()->volume() - type->magazine_well, 0_ml );
5162 }
5163
5164 if( is_gun() ) {
5165 for( const item *elem : gunmods() ) {
5166 ret += elem->volume( true );
5167 }
5168
5169 // TODO: implement stock_length property for guns
5171 // consider only the base size of the gun (without mods)
5172 ret -= ( type->volume / 3 );
5173 }
5174
5176 ret -= type->gun->barrel_length;
5177 }
5178 }
5179
5180 return ret;
5181}
static const std::string flag_COLLAPSIBLE_STOCK("COLLAPSIBLE_STOCK")
units::volume magazine_well
Volume above which the magazine starts to protrude from the item and add extra volume.
Definition: itype.h:1026
units::volume integral_volume
Space consumed when integrated as part of another item (defaults to volume) CAUTION: value given is f...
Definition: itype.h:979

References charges, components, contents, corpse, corpse_volume(), count_by_charges(), debugmsg, flag_COLLAPSIBLE_STOCK(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_volume, is_corpse(), is_craft(), is_gun(), is_null(), item_contents::item_size_modifier(), itype_barrel_small, units::legacy_volume_factor, LIQUID, made_of(), magazine_current(), itype::magazine_well, num, cata::hash64_detail::ret, itype::rigid, itype::stack_size, type, typeId(), volume(), and itype::volume.

Referenced by activity_on_turn_move_loot(), map::add_item_or_charges(), ranged::aim_cap_from_volume(), attack_cost(), basic_info(), veh_interact::calc_overview(), holster_actor::can_holster(), charges_per_volume(), comestible_inventory_preset::comestible_inventory_preset(), vehicle_part::consume_energy(), salvage_actor::cut_up(), Character::deal_damage(), npc::drop_items(), drop_or_embed_projectile(), fetch_activity(), iexamine::fvat_empty(), Character::get_acquirable_energy(), get_encumber_when_containing(), ranged::get_weapon_dispersion(), monexamine::give_items_to(), repair_item_actor::handle_components(), Character::item_handling_cost(), mdeath::jabberwock(), iexamine::keg(), Character::melee_special_effects(), move_cost_cart(), move_cost_inv(), iexamine::nanofab(), npc_pickup_from_stack(), pickup::obtain_and_tokenize_items(), Character::on_dodge(), on_wield(), vehicle::operate_scoop(), pick_one_up(), pickup::pick_up(), iexamine::pour_into_keg(), Character::power_rating(), process_corpse(), iuse::radiocar(), ready_to_revive(), pickup::reorder_for_dropping(), item_pricing::set_values(), npc::shop_restock(), smash(), holster_actor::store(), npc::stow_item(), stumble(), Character::takeoff(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), salvage_actor::time_to_cut_up(), tname(), salvage_actor::try_to_cut_up(), Character::update_bodytemp(), salvage_actor::valid_to_cut_up(), volume(), inventory::volume_without(), and wash_items().

◆ weight()

units::mass item::weight ( bool  include_contents = true,
bool  integral = false 
) const

Definition at line 4966 of file item.cpp.

4967{
4968 if( is_null() ) {
4969 return 0_gram;
4970 }
4971
4972 // Items that don't drop aren't really there, they're items just for ease of implementation
4973 if( has_flag( flag_NO_DROP ) ) {
4974 return 0_gram;
4975 }
4976
4977 if( is_craft() ) {
4978 units::mass ret = 0_gram;
4979 for( const item &it : components ) {
4980 ret += it.weight();
4981 }
4982 return ret;
4983 }
4984
4986 std::string local_str_mass = integral ? get_var( "integral_weight" ) : get_var( "weight" );
4987 if( local_str_mass.empty() ) {
4988 ret = integral ? type->integral_weight : type->weight;
4989 } else {
4990 ret = units::from_milligram( std::stoll( local_str_mass ) );
4991 }
4992
4993 if( has_flag( flag_REDUCED_WEIGHT ) ) {
4994 ret *= 0.75;
4995 }
4996
4997 // if this is a gun apply all of its gunmods' weight multipliers
4998 if( is_gun() ) {
4999 for( const item *mod : gunmods() ) {
5000 ret *= mod->type->gunmod->weight_multiplier;
5001 }
5002 }
5003
5004 if( count_by_charges() ) {
5005 ret *= charges;
5006
5007 } else if( is_corpse() ) {
5008 assert( corpse ); // To appease static analysis
5009 ret = corpse->weight;
5011 ret *= 0.75;
5012 }
5013 if( has_flag( flag_QUARTERED ) ) {
5014 ret /= 4;
5015 }
5016 if( has_flag( flag_GIBBED ) ) {
5017 ret *= 0.85;
5018 }
5019 if( has_flag( flag_SKINNED ) ) {
5020 ret *= 0.85;
5021 }
5022
5023 } else if( magazine_integral() && !is_magazine() ) {
5024 if( ammo_current() == itype_plut_cell ) {
5025 units::mass w = ( *ammo_types().begin() )->default_ammotype()->weight;
5027 } else if( ammo_data() ) {
5029 }
5030 }
5031
5032 // if this is an ammo belt add the weight of any implicitly contained linkages
5033 if( is_magazine() && type->magazine->linkage ) {
5034 item links( *type->magazine->linkage );
5035 links.charges = ammo_remaining();
5036 ret += links.weight();
5037 }
5038
5039 // reduce weight for sawn-off weapons capped to the apportioned weight of the barrel
5041 const units::volume b = type->gun->barrel_length;
5042 const units::mass max_barrel_weight = units::from_gram( to_milliliter( b ) );
5043 const units::mass barrel_weight = units::from_gram( b.value() * type->weight.value() /
5044 type->volume.value() );
5045 ret -= std::min( max_barrel_weight, barrel_weight );
5046 }
5047
5048 if( is_gun() ) {
5049 for( const item *elem : gunmods() ) {
5050 ret += elem->weight( true, true );
5051 }
5052 if( !magazine_integral() && magazine_current() ) {
5053 ret += std::max( magazine_current()->weight(), 0_gram );
5054 }
5055 } else if( include_contents ) {
5057 }
5058
5059 return ret;
5060}
units::mass item_weight_modifier() const
static const std::string flag_NO_DROP("NO_DROP")
static const std::string flag_REDUCED_WEIGHT("REDUCED_WEIGHT")
static const itype_id itype_plut_cell("plut_cell")
constexpr double b
Definition: magic.cpp:1031
constexpr value_type to_milliliter(const quantity< value_type, volume_in_milliliter_tag > &v)
Definition: units_volume.h:38
constexpr quantity< value_type, mass_in_milligram_tag > from_milligram(const value_type v)
Definition: units_mass.h:34
constexpr quantity< value_type, mass_in_milligram_tag > from_gram(const value_type v)
Definition: units_mass.h:41
units::mass integral_weight
Weight difference with the part it replaces for mods.
Definition: itype.h:967
units::mass weight
Definition: mtype.h:264

References ammo_current(), ammo_data(), ammo_remaining(), ammo_types(), b, charges, components, contents, corpse, count_by_charges(), flag_FIELD_DRESS(), flag_FIELD_DRESS_FAILED(), flag_GIBBED(), flag_NO_DROP(), flag_QUARTERED(), flag_REDUCED_WEIGHT(), flag_SKINNED(), units::from_gram(), units::from_milligram(), get_var(), itype::gun, gunmod_find(), gunmods(), has_flag(), itype::integral_weight, is_corpse(), is_craft(), is_gun(), is_magazine(), is_null(), item_contents::item_weight_modifier(), itype_barrel_small, itype_plut_cell, itype::magazine, magazine_current(), magazine_integral(), PLUTONIUM_CHARGES, cata::hash64_detail::ret, units::to_milliliter(), type, units::quantity< V, U >::value(), itype::volume, weight(), itype::weight, and mtype::weight.

Referenced by monexamine::add_armor(), attack_cost(), basic_info(), can_do_activity_there(), holster_actor::can_holster(), Character::can_pick_weight(), veh_interact::can_remove_part(), pickup::cost_to_move_item(), npc::drop_items(), fetch_activity(), funnel_charges_per_turn(), Character::get_acquirable_energy(), Character::get_weight(), monexamine::give_items_to(), is_two_handed(), lift_strength(), Character::melee_attack(), npc_pickup_from_stack(), pick_one_up(), pickup::pick_up(), advanced_inventory::query_charges(), iuse::radiocar(), item_pricing::set_values(), smash(), holster_actor::store(), stumble(), ranged::throw_item(), Character::throw_range(), ranged::throwing_dispersion(), trap::triggered_by_item(), veh_interact::update_part_requirements(), weight(), Character::weight_carried_reduced_by(), and inventory::weight_without().

◆ wheel_area()

int item::wheel_area ( ) const

Returns the total area of this wheel or 0 if it isn't one.

Definition at line 6819 of file item.cpp.

6820{
6821 return is_wheel() ? type->wheel->diameter * type->wheel->width : 0;
6822}

References is_wheel(), type, and itype::wheel.

◆ will_explode_in_fire()

bool item::will_explode_in_fire ( ) const

Definition at line 8742 of file item.cpp.

8743{
8744 if( type->explode_in_fire ) {
8745 return true;
8746 }
8747
8748 if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
8749 return true;
8750 }
8751
8752 // Most containers do nothing to protect the contents from fire
8753 if( !is_magazine() || !type->magazine->protects_contents ) {
8754 return has_item_with( [&]( const item & it ) {
8755 return this != &it && it.will_explode_in_fire();
8756 } );
8757 }
8758
8759 return false;
8760}
bool will_explode_in_fire() const
Definition: item.cpp:8742
bool explode_in_fire
Definition: itype.h:947

References itype::ammo, itype::explode_in_fire, visitable< item >::has_item_with(), is_magazine(), itype::magazine, type, and will_explode_in_fire().

Referenced by will_explode_in_fire().

◆ wind_resist()

int item::wind_resist ( ) const

How resistant clothes made of this material are to wind (0-100)

Definition at line 6788 of file item.cpp.

6789{
6790 std::vector<const material_type *> materials = made_of_types();
6791 if( materials.empty() ) {
6792 debugmsg( "Called item::wind_resist on an item (%s [%s]) made of nothing!", tname(), typeId() );
6793 return 99;
6794 }
6795
6796 int best = -1;
6797 for( const material_type *mat : materials ) {
6798 std::optional<int> resistance = mat->wind_resist();
6799 if( resistance && *resistance > best ) {
6800 best = *resistance;
6801 }
6802 }
6803
6804 // Default to 99% effective
6805 if( best == -1 ) {
6806 return 99;
6807 }
6808
6809 return best;
6810}

References debugmsg, made_of_types(), tname(), and typeId().

Referenced by wind_resistance_from_item_list().

Member Data Documentation

◆ activated_by

safe_reference<Character> item::activated_by

Definition at line 2242 of file item.h.

Referenced by detonate(), itype::invoke(), and explosion_iuse::use().

◆ active

bool item::active = false

Definition at line 2241 of file item.h.

Referenced by activate(), Character::activate_bionic(), map::add_item(), npc::alt_attack(), iexamine::autodoc(), basic_info(), burn(), iuse::c4(), iuse::cable_attach(), holster_actor::can_holster(), countdown_actor::can_use(), check_litcig(), color_in_inventory(), Character::consume_remote_fuel(), deactivate(), mdeath::detonate(), iuse::dive_tank(), iuse::ehandcuffs(), iuse::einktabletpc(), explosion_handler::emp_blast(), Character::find_remote_fuel(), iuse::firecracker(), iuse::firecracker_pack(), iuse::fish_trap(), iuse::gasmask(), iuse::geiger(), iuse::granade(), Character::has_active_item(), io(), enchantment::is_active(), item(), mattack::kamikaze(), make_gun_projectile(), activity_handlers::make_zlave_finish(), iuse::mininuke(), iuse::molotov_lit(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), needs_processing(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_takeoff(), on_wear(), iuse::pack_item(), process_extinguish(), process_internal(), process_litcig(), process_tool(), process_UPS(), process_wet(), vehicle_part::properties_to_item(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), read(), iuse::remoteveh(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::shocktonfa_off(), iuse::shocktonfa_on(), sleep(), iuse::smoking(), iuse::solarpack_off(), stacks_with(), holster_actor::store(), ranged::throw_item(), iuse::throwable_extinguisher_act(), tname(), toolweapon_off(), toolweapon_on(), iuse::tow_attach(), iuse::towel_common(), avatar_funcs::unload_item(), iuse::unpack_item(), iuse_transform::use(), countdown_actor::use(), fireweapon_off_actor::use(), musical_instrument_actor::use(), and npc::value().

◆ anchor

safe_reference_anchor item::anchor
private

Definition at line 2173 of file item.h.

Referenced by get_safe_reference().

◆ bday

time_point item::bday
private

The time the item was created.

Definition at line 2231 of file item.h.

Referenced by birthday(), io(), item(), legacy_fast_forward_time(), and set_birthday().

◆ burnt

int item::burnt = 0

◆ charges

int item::charges

Definition at line 2203 of file item.h.

Referenced by iuse::acidbomb_act(), act_vehicle_siphon(), Character::activate_bionic(), activity_on_turn_wear(), vehicle::add_charges(), vehicle::add_item(), map::add_item_or_charges(), avatar_funcs::add_or_drop_with_msg(), add_rain_to_container(), ammo_consume(), vehicle_part::ammo_consume(), ammo_remaining(), vehicle_part::ammo_remaining(), ammo_set(), ammo_unset(), item_stack::amount_can_fit(), jmapgen_liquid_item::apply(), are_requirements_nearby(), iuse::arrow_flammable(), basic_info(), burn(), iuse::c4(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), comestible_inventory_preset::comestible_inventory_preset(), complete_craft(), crafting::complete_disassemble(), veh_interact::complete_vehicle(), Character::consume_charges(), vehicle_part::consume_energy(), Character::consume_item(), liquid_handler::consume_liquid(), Character::consume_med(), game_menus::inv::container_for(), count(), activity_handlers::craft_do_turn(), recipe::create_byproducts(), recipe::create_result(), recipe::create_results(), detonate(), mdeath::detonate(), display_name(), iuse::dive_tank(), anonymous_namespace{iexamine.cpp}::atm_menu::do_purchase_card(), npc::do_reload(), veh_interact::do_siphon(), anonymous_namespace{iexamine.cpp}::atm_menu::do_transfer_all_money(), move_items_activity_actor::do_turn(), throw_activity_actor::do_turn(), anonymous_namespace{iexamine.cpp}::atm_menu::do_withdraw_money(), map::draw_lab(), iuse::ehandcuffs(), explosion_handler::emp_blast(), iuse::eyedrops(), farm_action(), Character::feed_furnace_with(), fetch_activity(), talk_function::field_harvest(), activity_handlers::fill_liquid_do_turn(), fill_with(), final_info(), wash_activity_actor::finish(), heal_actor::finish_using(), iuse::firecracker(), iuse::firecracker_act(), iuse::firecracker_pack(), iuse::firecracker_pack_act(), iuse::fish_trap(), character_funcs::fmt_wielded_weapon(), food_info(), for_each_item_in_both(), inventory::form_from_map(), Character::fuel_bionic_with(), funnel_charges_per_turn(), iexamine::fvat_empty(), iexamine::fvat_full(), iuse::gasmask(), Character::get_acquirable_energy(), activity_handlers::repair_activity_hack::anonymous_namespace{activity_handlers.cpp}::get_fake_tool(), iexamine::get_harvest_items(), liquid_handler::get_liquid_target(), get_remaining_capacity_for_liquid(), inventory_entry::get_selected_charges(), json_item_substitution::get_substitution(), monexamine::give_items_to(), iuse::granade(), iuse::granade_act(), iuse::grenade_inc_act(), hackveh(), liquid_handler::handle_all_liquid(), liquid_handler::handle_liquid_from_container(), pickup::handle_spillable_contents(), has_infinite_charges(), Character::i_add_to_container(), io(), item(), Character::item_reload_cost(), iexamine::keg(), med_info(), merge_charges(), Item_factory::migrate_item(), activity_handlers::milk_finish(), iuse::mininuke(), mod_charges(), mod_damage(), Item_modifier::modify(), iuse::molotov_lit(), advanced_inventory::move_all_items(), advanced_inventory::move_content(), move_item(), iuse::multicooker(), npc_throw(), vehicle::operate_planter(), operator<(), parse_tags(), iexamine::pay_gas(), liquid_handler::perform_liquid_transfer(), pick_one_up(), pickup::pick_up(), map::place_gas_pump(), map::place_toilet(), Character::pour_into(), iexamine::pour_into_keg(), advanced_inventory::print_items(), game::process_artifact(), process_cable(), Character::process_items(), relic_funcs::process_recharge_entry(), map::produce_sap(), vehicle_part::properties_to_item(), item_reload_option::qty(), advanced_inventory::query_charges(), player::reduce_charges(), bandolier_actor::reload(), reload(), remove_ammo(), reset_cable(), mattack::riotbot(), talk_effect_fun_t::set_bulk_trade_accept(), set_countdown(), iexamine::sign(), character_funcs::siphon(), smoker_activate(), map::spawn_an_item(), spell_effect::spawn_ethereal_item(), split(), stacks_with(), Character::suffer_from_bad_bionics(), iuse::tazer2(), Character::throw_range(), iuse::throwable_extinguisher_act(), ranged::throwing_dispersion(), tname(), npc_trading::trade(), npc_trading::transfer_items(), iexamine::tree_maple_tapped(), try_consume(), try_fuel_fire(), units_remaining(), avatar_funcs::unload_item(), inventory::update_quality_cache(), explosion_iuse::use(), place_monster_iuse::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), bandolier_actor::use(), emit_actor::use(), sew_advanced_actor::use(), basecamp::use_charges(), map::use_charges(), use_charges_from_furn(), iexamine::use_furn_fake_item(), volume(), iuse::water_purifier(), weight(), Character::weight_carried_reduced_by(), debug_menu::wishitem(), and memorial_logger::write().

◆ components

◆ contents

item_contents item::contents

Definition at line 2165 of file item.h.

Referenced by Character::absorb_hit(), act_vehicle_siphon(), computer_session::action_blood_anal(), computer_session::action_data_anal(), actualize_rot(), vehicle::add_item(), add_rain_to_container(), allow_crafting_component(), ammo_consume(), vehicle_part::ammo_consume(), vehicle_part::ammo_current(), ammo_data(), ammo_remaining(), vehicle_part::ammo_remaining(), vehicle_part::ammo_set(), ammo_unset(), vehicle_part::ammo_unset(), map::bash_items(), iuse::blood_draw(), activity_handlers::butcher_finish(), item_location::impl::item_in_container::calc_index(), veh_interact::calc_overview(), item_funcs::can_be_unloaded(), Character::can_consume(), can_holster(), bandolier_actor::can_store(), can_unload_liquid(), casings_handle(), complete_craft(), veh_interact::complete_vehicle(), Character::compute_nutrient_range(), Character::consume(), npc::consume_cbm_items(), vehicle_part::consume_energy(), contents_info(), contents_made_of(), salvage_actor::cut_up(), damage_item(), item_location::deserialize(), deserialize(), detonate(), display_name(), veh_interact::do_siphon(), avatar_action::eat(), empty_buckets(), computer_session::failure_destroy_blood(), computer_session::failure_destroy_data(), fill_with(), final_info(), character_funcs::find_ammo_helper(), character_funcs::fmt_wielded_weapon(), get_category(), Character::get_consumable_from(), get_contained(), get_encumber(), get_free_mod_locations(), liquid_handler::get_liquid_target(), get_quality(), get_remaining_capacity_for_liquid(), json_item_substitution::get_substitution(), trading_window::get_var_trade(), goes_bad_after_opening(), gunmods(), liquid_handler::handle_liquid_from_container(), Character::handle_melee_wear(), handle_problematic_pickup(), pickup::handle_spillable_contents(), has_effect_when_carried(), Character::i_add_to_container(), info(), is_ammo_container(), is_container_empty(), is_container_full(), advanced_inv_area::is_container_valid(), is_dangerous(), is_food_container(), is_funnel_container(), is_med_container(), is_reloadable_helper(), item_has_uses_recursive(), Character::item_reload_cost(), magazine_current(), item_location::impl::item_in_container::make_dirty(), Character::melee_special_effects(), Item_factory::migrate_item(), activity_handlers::mind_splicer_finish(), advanced_inventory::move_content(), iuse::multicooker(), needs_processing(), on_pickup(), operator<(), peek_related_recipe(), put_in(), item_reload_option::qty(), qualities_info(), iuse::radiocar(), avatar_action::reload(), bandolier_actor::reload(), reload(), item_contents::remove_internal(), visitable< T >::remove_items_with(), character_funcs::select_ammo(), serialize(), advanced_inv_area::set_container(), map::smash_items(), spill_contents(), spoilage_sort_order(), stacks_with(), tname(), toolmods(), iexamine::tree_maple_tapped(), try_consume(), salvage_actor::try_to_cut_up(), character_funcs::try_wield_contents(), avatar_funcs::unload_item(), item_location::impl::item_in_container::unpack(), holster_actor::use(), bandolier_actor::use(), salvage_actor::valid_to_cut_up(), visit_internal(), volume(), iuse::water_purifier(), weight(), avatar::wield(), avatar_action::wield(), npc::wield_better_weapon(), and memorial_logger::write().

◆ corpse

◆ corpse_name

std::string item::corpse_name
private

Definition at line 2177 of file item.h.

Referenced by get_corpse_name(), io(), and type_name().

◆ craft_data_

◆ curammo

const itype* item::curammo = nullptr
private

Definition at line 2174 of file item.h.

Referenced by ammo_consume(), ammo_data(), ammo_set(), ammo_unset(), gun_info(), io(), and reload().

◆ damage_

int item::damage_ = 0
private

Definition at line 2236 of file item.h.

Referenced by basic_info(), damage(), damage_level(), io(), mod_damage(), on_damage(), set_damage(), and stacks_with().

◆ drop_token

pimpl<item_drop_token> item::drop_token

Two items are dropped in same "batch" if they have identical drop tokens Ideally, this would be stored outside item class.

Definition at line 2254 of file item.h.

Referenced by pickup::obtain_and_tokenize_items(), and pickup::optimize_pickup().

◆ encumbrance_update_

bool item::encumbrance_update_ = false

Definition at line 2219 of file item.h.

Referenced by on_contents_changed().

◆ energy

units::energy item::energy

Definition at line 2204 of file item.h.

Referenced by energy_remaining(), io(), mod_energy(), and process_tool().

◆ faults

◆ frequency

int item::frequency = 0

Definition at line 2209 of file item.h.

Referenced by io(), and iuse::radio_on().

◆ INFINITE_CHARGES

◆ invlet

◆ irradiation

int item::irradiation = 0

Definition at line 2211 of file item.h.

Referenced by armor_fit_info(), and io().

◆ is_favorite

◆ item_counter

◆ item_tags

◆ item_vars

std::map<std::string, std::string> item::item_vars
private

◆ last_rot_check

time_point item::last_rot_check = calendar::turn_zero
private

Time when the rot calculation was last performed.

Definition at line 2229 of file item.h.

Referenced by basic_info(), calc_rot(), io(), item(), legacy_fast_forward_time(), mod_last_rot_check(), process(), process_rot(), and set_relative_rot().

◆ light

light_emission item::light = nolight
private

Definition at line 2237 of file item.h.

Referenced by getlight(), io(), and is_emissive().

◆ mission_id

int item::mission_id = -1

◆ old_owner

faction_id item::old_owner = faction_id::NULL_ID()
mutableprivate

◆ owner

◆ player_id

int item::player_id = -1

Definition at line 2214 of file item.h.

Referenced by mission::deserialize(), io(), and mission::serialize().

◆ poison

◆ recipe_charges

int item::recipe_charges = 1

Definition at line 2206 of file item.h.

Referenced by complete_craft(), Character::compute_effective_nutrients(), and io().

◆ relic_data

◆ rot

time_duration item::rot = 0_turns
private

Accumulated rot, expressed as time the item has been in standard temperature.

It is compared to shelf life (islot_comestible::spoils) to decide if the item is rotten.

Definition at line 2227 of file item.h.

Referenced by basic_info(), minimum_freshness_duration(), spoilage_sort_order(), and stacks_with().

◆ snip_id

snippet_id item::snip_id = snippet_id::NULL_ID()

Definition at line 2210 of file item.h.

Referenced by basic_info(), io(), item(), and set_snippet().

◆ techniques

std::set<matec_id> item::techniques
private

Definition at line 2178 of file item.h.

Referenced by add_technique(), combat_info(), get_techniques(), has_technique(), io(), and stacks_with().

◆ type

const itype* item::type

Definition at line 2164 of file item.h.

Referenced by activate(), npc::activate_item(), actualize_rot(), game::add_artifact_dreams(), map::add_item(), add_monsters(), iuse::adrenaline_injector(), alcohol(), ammo_capacity(), ammo_data(), ammo_default(), ammo_effects(), ammo_required(), ammo_set(), ammo_type(), ammo_types(), iuse::antiasthmatic(), iuse::antibiotic(), iuse::anticonvulsant(), iuse::antifungal(), iuse::antiparasitic(), apply_lock_picking_tool(), armor_info(), armor_protection_info(), iuse::artifact(), iexamine::autodoc(), base_damage_thrown(), base_volume(), basic_info(), battery_info(), iuse::bell(), bionic_info(), talk_function::bionic_install(), iuse::blech(), iuse::blech_because_unclean(), iuse::blood_draw(), iuse::boltcutters(), book_info(), brewing_results(), brewing_time(), mdeath::broken(), burn(), Character::burn_fuel(), iuse::c4(), character_effects::calc_focus_equilibrium(), iuse::call_of_tindalos(), iuse::camera(), item_funcs::can_be_unloaded(), can_contain(), can_do_activity_there(), Character::can_eat(), iuse::can_goo(), can_holster(), npc::can_read(), Character::can_reload(), bandolier_actor::can_store(), fireweapon_off_actor::can_use(), manualnoise_actor::can_use(), install_bionic_actor::can_use(), saw_barrel_actor::can_use_on(), saw_stock_actor::can_use_on(), iuse::capture_monster_act(), charges_per_volume(), check_art_charge_req(), iuse::chew(), iuse::chop_logs(), chop_plank_activity(), iuse::chop_tree(), chop_tree_activity(), iuse::clear_rubble(), color(), color_in_inventory(), combat_info(), common_ammo_default(), prepared_item_consumption::consume(), Character::consume_effects(), Character::consume_med(), iuse::contacts(), contain_monster(), container_info(), convert(), count_by_charges(), activity_handlers::cracking_do_turn(), Character::crit_chance(), iuse::crowbar(), damage_melee(), iuse::datura(), deactivate(), deserialize(), mission::deserialize(), player_morale::morale_point::deserialize(), addiction::deserialize(), vehicle::deserialize(), detonate(), iuse::dig(), iuse::dig_channel(), iuse::directional_antenna(), iuse::directional_hologram(), display_name(), iuse::dive_tank(), avatar::do_read(), iuse::dog_whistle(), game::dump_stats(), Character::eat(), mattack::eat_food(), iuse::ecig(), iuse::ehandcuffs(), iuse::einktabletpc(), emit_radio_signal(), engine_displacement(), Character::enumerate_unmet_requirements(), iuse::extinguisher(), iuse::eyedrops(), faults_potential(), talk_function::field_harvest(), iuse::fill_pit(), final_info(), find_armor_data(), find_best_lock_picking_tool(), npc::find_dangerous_explosives(), npc::finish_read(), heal_actor::finish_using(), avatar_action::fire_wielded_weapon(), iuse::firecracker(), iexamine::fireplace(), iuse::flumed(), iuse::flusleep(), iuse::foodperson(), fuel_energy(), fuel_pump_terrain(), iuse::fungicide(), iuse::gasmask(), iuse::geiger(), json_talk_topic::gen_responses(), Character::get_acquirable_energy(), activatable_inventory_preset::get_action_name(), bionic_install_preset::get_anesth_amount(), bionic_uninstall_preset::get_anesth_amount(), get_available_recipes(), get_base_env_resist(), get_base_env_resist_w_filter(), read_inventory_preset::get_book(), character_funcs::get_book_fun_for(), avatar::get_book_reader(), get_category(), get_chapters(), get_clothing_mod_val(), get_comestible(), get_comestible_fun(), get_container_capacity(), activatable_inventory_preset::get_denial(), read_inventory_preset::get_denial(), bionic_install_preset::get_denial(), bionic_install_surgeon_preset::get_denial(), bionic_uninstall_preset::get_denial(), comestible_inventory_preset::get_edible_comestible(), get_encumber_when_containing(), get_env_resist(), bionic_install_preset::get_failure_chance(), bionic_install_surgeon_preset::get_failure_chance(), bionic_uninstall_preset::get_failure_chance(), ranged::get_fastest_sight(), get_gun_ups_drain(), npc::get_healing_item(), Character::get_hit_weapon(), get_layer(), get_min_str(), get_mod_locations(), ranged::get_most_accurate_sight(), zone_manager::get_near_zone_type_for_item(), bionic_install_preset::get_operation_duration(), bionic_install_surgeon_preset::get_operation_duration(), bionic_uninstall_preset::get_operation_duration(), comestible_inventory_preset::get_order(), get_pet_armor_bodytype(), get_pet_armor_max_vol(), get_pet_armor_min_vol(), get_plant_epoch(), get_plant_name(), get_property_int64_t(), get_property_string(), get_qualities(), get_quality(), get_reload_time(), get_remaining_capacity_for_liquid(), get_storage(), get_techniques(), get_thickness(), get_total_capacity(), get_use_internal(), plot_options::get_zone_name_suggestion(), getGasDiscountCardQuality(), getlight_emit(), goes_bad_after_opening(), iuse::granade(), iuse::granade_act(), gun_damage(), gun_dispersion(), gun_info(), gun_noise(), gun_range(), gun_recoil(), gun_recoil_multiplier(), iuse::gun_repair(), gun_skill(), npc_ai::gun_value(), gunmod_info(), avatar_funcs::gunmod_installation_odds(), iuse::hacksaw(), iuse::hairkit(), iuse::hammer(), iuse::handle_ground_graffiti(), ranged::handle_gun_damage(), has_effect_when_carried(), has_effect_when_wielded(), has_effect_when_worn(), has_explosion_data(), has_flag(), npc::has_healing_options(), has_property(), has_technique(), has_use(), npc::heal_player(), npc::heal_self(), iuse::honeycomb(), in_its_container(), countdown_actor::info(), info(), iuse::inhaler(), inherit_flags(), Character::invoke_item(), avatar::invoke_item(), npc::invoke_item(), io(), is_ammo(), is_artifact(), is_bandolier(), is_battery(), is_bionic(), is_book(), is_brewable(), is_bucket(), is_container(), is_deployable(), is_emissive(), is_engine(), is_fuel(), is_gun(), is_gunmod(), is_holster(), is_magazine(), is_non_resealable_container(), is_null(), avatar_funcs::is_pet_food(), is_seed(), activatable_inventory_preset::is_shown(), is_tool(), is_toolmod(), is_transformable(), is_upgrade(), is_watertight_container(), is_wheel(), item(), item_has_uses_recursive(), Character::item_reload_cost(), item_reload_option::item_reload_option(), iuse::jackhammer(), iuse::jet_injector(), submap::load(), iuse::lumber(), iuse::ma_manual(), made_of(), magazine_compatible(), magazine_default(), magazine_info(), magazine_integral(), iuse::makemound(), mark_chapter_as_read(), iuse::marloss(), iuse::marloss_gel(), iuse::marloss_seed(), max_damage(), iuse::meditate(), Character::meets_requirements(), Character::meets_stat_requirements(), iuse::melatonin_tablet(), npc_ai::melee_value(), iuse::meth(), mill_load_food(), min_damage(), iuse::mind_splicer(), mine_activity(), minimum_freshness_duration(), iuse::mininuke(), mod_damage(), mod_energy(), Item_modifier::modify(), iuse::modify_grid_connections(), Character::modify_morale(), iuse::mop(), avatar_action::move(), iuse::mp3(), iuse::mp3_on(), iuse::multicooker(), mutagen_common_checks(), iuse::mycus(), iuse::noise_emitter_off(), iuse::noise_emitter_on(), on_contents_changed(), on_drop(), on_pickup(), on_takeoff(), on_wear(), on_wield(), operator<(), iuse::oxygen_bottle(), iuse::pheromone(), iuse::plantblech(), iuse::poison(), iuse::portal(), Character::pour_into(), price(), process(), game::process_artifact(), process_cable(), process_extinguish(), process_internal(), Character::process_items(), process_tool(), process_vehicle_items(), process_wet(), vehicle_part::properties_to_item(), iuse::prozac(), iuse::purifier(), iuse::purify_iv(), iuse::purify_smart(), item_reload_option::qty(), qualities_info(), quality_of(), plot_options::query_seed(), iuse::radglove(), iuse::radio_off(), iuse::radio_on(), iuse::radiocar(), iuse::radiocaron(), iuse::radiocontrol(), examine_item_menu::rate_action_use(), rate_food(), read(), avatar::read(), read_inventory_preset::read_inventory_preset(), avatar_action::reload(), reload(), activity_handlers::reload_finish(), iuse::remoteveh(), repair_item_actor::repair_recipe_difficulty(), repaired_with(), reset_cable(), mattack::riotbot(), iuse::rm13armor_off(), iuse::rm13armor_on(), iuse::robotcontrol(), iexamine::safe(), iuse::seed(), mission::serialize(), player_morale::morale_point::serialize(), addiction::serialize(), vehicle::serialize(), iuse::sewage(), iuse::shavekit(), activity_handlers::shear_finish(), iuse::shocktonfa_off(), sight_dispersion(), simulate_burn(), iuse::siphon(), skim_book_msg(), iuse::sleep(), smoker_activate(), iuse::smoking(), activity_handlers::spellcasting_finish(), spoilage_sort_order(), stacks_with(), activity_handlers::start_fire_do_turn(), activity_handlers::start_fire_finish(), npc::start_read(), iuse::stimpack(), iuse::strong_antibiotic(), symbol(), iuse::talking_doll(), iuse::tazer(), iuse::teleport(), iuse::thorazine(), ranged::throw_item(), ranged::time_to_attack(), npc::time_to_read(), avatar::time_to_read(), tname(), iuse::toolmod_attach(), toolweapon_off(), toolweapon_on(), iuse::towel_common(), try_consume(), type_name(), typeId(), avatar_funcs::unload_item(), target_ui::update_ammo_range_from_gun_mode(), update_clothing_mod_val(), charger_tile::update_internal(), iuse_transform::use(), countdown_actor::use(), consume_drug_iuse::use(), pick_lock_actor::use(), firestarter_actor::use(), fireweapon_off_actor::use(), fireweapon_on_actor::use(), manualnoise_actor::use(), heal_actor::use(), mutagen_actor::use(), mutagen_iv_actor::use(), install_bionic_actor::use(), avatar_funcs::use_item(), vehicle::use_monster_capture(), iuse::vaccine(), npc::value(), iuse::vibe(), volume(), iuse::vortex(), iuse::weak_antibiotic(), npc_ai::weapon_value(), iuse::weed_cake(), weight(), wheel_area(), vehicle_part::wheel_diameter(), vehicle_part::wheel_width(), npc::wield_better_weapon(), npc_ai::wielded_value(), npc::will_accept_from_player(), will_explode_in_fire(), and iuse::xanax().


The documentation for this class was generated from the following files: